Skip to content
Advertisement

symbol can’t be printed in GET php

I have a link like this:

http://domain.com/page.php?product=brown+rice

And then in the page.php page I GET the product:

 $product = $_GET['product'];



 <?php echo $product; ?>

But it only prints : brown rice without the +

How to get the + in the get method?

Advertisement

Answer

First, I will replace it with any different symbol before I pass it in the link:

For example:

     http://domain.com/page.php?product='.str_replace("+","_",$obj->items).'"

And then in the page.php I will turn it back to the original symbol:

  $product= str_replace("_","+",$_GET['product']);

This method will only replace all products which have + symbol in the url. And when you GET it, it will check if the name of the product will have the symbol.

I hope that you understand and it helps

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement