Forum Moderators: coopster

Message Too Old, No Replies

PHP Code to deal with the '&' symbol.

         

matthewamzn

4:04 am on Oct 6, 2005 (gmt 0)

10+ Year Member



I have a mysql database that I search with php. I'm using the code below to get my search terms. It can handle apostrophes but not the '&' symbol. Is there another php code that will strip this symbol?

$variable = @$_GET['b'];
$variable = addslashes($variable);

coopster

1:17 pm on Oct 6, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You want to strip out the ampersand from any given variable for your query statements? addslashes [php.net], or better yet in this case mysql_real_escape_string [php.net], will allow the ampersand to be a character that is searched within any given string safely, but if you truly want any ampersands removed you could use something like str_replace() [php.net].

matthewamzn

4:33 am on Oct 7, 2005 (gmt 0)

10+ Year Member



Thanks, I've got it working now.