Re[2]: [PHP] Whimper, help :)
| From: | Tom Rogers | Date: | Wed, 04 Dec 2002 17:18:25 +0000 |
| Subject: | Re[2]: [PHP] Whimper, help :) | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-127004@lists.php.net to get a copy of this message | ||
Hi,
Wednesday, December 4, 2002, 3:12:41 PM, you wrote:
JTJ> Tom,
JTJ> Anyone,
JTJ> No I'm not looking for a ", I'm trying to pass double quotes into MySQL.
JTJ> Like I said, it works when debugging:
here is a function to clean up your search string, a bit long winded but it
should work :)
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;
}
//simulate input
$test = addslashes(' +test "hello maria" fish '."-O'Brian 'big
\" test'");
$list = clean_search_string($test);
echo $list.'<br>';
--
regards,
Tom