Pavel
Pavel

Reputation: 5353

How to escape '/' in codeigniter, php?

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?

Upvotes: 2

Views: 1988

Answers (2)

lindy
lindy

Reputation: 21

Just battled the same issue and the str_replace method didn't work. I got it to accept the forward slash by adding it to the default product_name_rules parameter.

$this->cart->product_name_rules = '\/\.\:\-_ a-z0-9';

Upvotes: 2

Russell Dias
Russell Dias

Reputation: 73342

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

Thats works for some of my CI applications.

Upvotes: 0

Related Questions