On Fri, 09 Jun 2006 14:53:09 +0200, sam <php@xxxxxxxx> wrote:
$str='bass "electric organ" bagpipes'; $parser($str); $query="SELECT * FROM table WHERE tb_instr = "bass" > AND tb_instr = "electric organ" //<<quoted phrase > AND tb_instr = "bagpipes"; Anybody know where I can just copy code that will do the above? thanks
I once for just the fun of it, made a regular expression to solve this kind of problem. I haven't tried it in production enviroment, but only on some basic examples. It should support both single and double quotes. $str = 'bass "electric organ" bagpipes'; preg_match_all("/(?<=('|\"))[^\\1]+(?=\\1)|[^ \"']+/",$str,$match); /* $match[0] Array ( [0] => bass [1] => electric organ [2] => bagpipes ) */ foreach($match[0] as $key => $value) { $match[0][$key] = 'tb_instr = "'.mysql_escape_string($value).'"'; } $sql = "SELECT * FROM table WHERE ".implode(' AND ',$match[0]); print($sql); //SELECT * FROM table WHERE tb_instr = "bass" AND //tb_instr = "electric organ" AND tb_instr = "bagpipes" -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php