views:

44

answers:

1

Hey guys. I'm having this silly issue with inserting text with forwardslash into cart in codeigniter. When it's plain string it's fine but when inserting, say, "compact / compact" it's not doing it. My guess is that '/' needs to be somehow escaped. I tried hmtlspecialchars(), htmlentities() and even addslashes() - none of the worked. Does anyone know how to do that in php?

When I'm inserting something to cart, I'm doing it like this:

$release_barcode = $this->uri->segment(3);

        $release = $this->Lists_model->get_release_by_barcode($release_barcode);

            foreach($release as $row):
            {
                 $barcode = $row->EAN_UPC;
                 $price = $row->product_price;
                 $currency = $row->product_currency;
                 $artist_name = $row->artist_name;
                 $label_name = $row->label_name;
                 $release_name = $row->title;
                 $cover = $row->cover;
                 $item_name = $artist_name.', '.$release_name.', '.$label_name;

                 $data = array(
                                  'id'      => $barcode,
                                  'qty'     => 1,
                                  'price'   => $price,
                                  'name'    => $artist_name,
                                  'options' => array('pic' => $cover, 'currency' => $currency)
                              );

                 $this->cart->insert($data);


            }
            endforeach;

            $this->display_cart();

Perhaps I'm doing something wrong here. Can you give me a hint please?

A: 

$string = str_replace('/', '\/', $string);

Thats works for some of my CI applications.

Russell Dias
A forward slash shouldn't require escaping.
halfdan
I understand that. However, why CI requires this is beyond me. But, for certain applications the above single line helps me with the problem. I'll chase it up on the CI forums I think.
Russell Dias