Re: magic quotes
| From: | Tom Rogers | Date: | Wed, 04 Dec 2002 17:40:37 +0000 |
| Subject: | Re: magic quotes | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-127009@lists.php.net to get a copy of this message | ||
Hi,
Thursday, December 5, 2002, 3:39:20 AM, you wrote:
JTJ> What are magic quotes? Will this help me?
JTJ>
JTJ> http://news.php.net/article.php?group=php.general&article=126934
JTJ> How is this different from stripslashes.
JTJ> I have RTF doc :)
JTJ>
JTJ> http://www.php.net/manual/en/function.get-magic-quotes-gpc.php
JTJ> Be gentil ::p
JTJ> --
JTJ> John Taylor-Johnston
JTJ> -----------------------------------------------------------------------------
JTJ> "If it's not open-source, it's Murphy's Law."
JTJ> - Université de Sherbrooke:
JTJ> http://compcanlit.ca/
magic quotes are slashes that are added to post and get data by PHP
That is probably what is stuffing up :)
I replied to an earlier thread with a possible solution but here it is again...
function clean_search_string($s){
$s = stripslashes($s);
$state = 'S';
$len = strlen($s);
$out = '';
$list = array();
for($i=0;$i<$len;$i++){
switch($state){
case 'S':
switch($s[$i]){
case ' ':
break;
case '"':
$state = 'Q';
break;
case "'":
$state = 'q';
break;
default:
$state = 'W';
$out .= $s[$i];
break;
}
break;
case 'W':
switch($s[$i]){
case ' ':
$state = 'S';
$out = addslashes($out);
$list[] = $out;
$out = '';
break;
default:
$out .= $s[$i];
break;
}
break;
case 'Q':
switch($s[$i]){
case '"':
$state = 'S';
$out =
'"'.addslashes($out).'"';
$list[] = $out;
$out = '';
break;
default:
$out .= $s[$i];
break;
}
break;
case 'q':
switch($s[$i]){
case "'":
$state = 'S';
$out =
'"'.addslashes($out).'"';
$list[] = $out;
$out = '';
break;
default:
$out .= $s[$i];
break;
}
break;
}
}
if(!empty($out)) $list[] = addslashes($out);;
$r = '';
$x = 0;
while(list($key,$val)=each($list)){
$r .= $val.' ';
}
return $r;
}
$test = addslashes(' +test "hello maria" fish '."-O'Brian 'big
\" test'");
$list = clean_search_string($test);
echo $list.'<br>';
you will then just need "SELECT.......... AGAINST '$list' .... "
--
regards,
Tom