removing plus sign ( + ) from url

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
azhan
Forum Commoner
Posts: 68
Joined: Fri Jun 27, 2008 6:05 am

removing plus sign ( + ) from url

Post by azhan »

Hello guys,

Im having this one problem of removing + sign from url, not the plus sign that generated by browser to separate each word. But plus sign from the content itself.

situation

on page 1, user choose medicine from drop down menu named --> HYDRO+NEOMYCIN (1/8 oz), which have plus sign inside it...

then the page execute to the next page like this... nextpage.php?q=$data

i called back the data by using GET function

$q = $_GET['q'];

but when i wanted to query it from mysql, it return no result...

surprisingly if i paste the name of the medicine directly during query...it does return result..

like this.... $search = mysql_query("SELECT * FROM medicine WHERE name LIKE 'HYDRO+NEOMYCIN (1/8 oz)'");

sadly it doesnt work if i query it by string like this
$search = mysql_query("SELECT * FROM medicine WHERE name LIKE '%$q%'");

I guess it must be sumthing wrong during the transfer via URL...

i try remove the + sign using urldecode, ereg_replace, str_replace...but all doesnt work

do anyone know how to?

thanks
Azhan
DaiLaughing
Forum Commoner
Posts: 76
Joined: Thu Jul 16, 2009 8:03 am

Re: removing plus sign ( + ) from url

Post by DaiLaughing »

I'm guessing it's because even using an & code introduces a character which GET already uses.

urlencode() seems to be a possible answer. I've not used it but have a look.
Post Reply