Posted by brendan on 09/07/05 17:32
"Sandman" <mr@sandman.net> wrote in message
news:mr-ECC27F.16230007092005@individual.net...> #!/usr/bin/php
> <?
> $string = "author:Jane Smith institution:university of Cambridge
year:1976";
> $m = preg_split("/\s*(\w+):/", $string, -1,
> PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE);
> for ($i=0;$i<=count($m)-1;$i+=2){
> $sql_query[] = $m[$i] . " = '" . $m[$i+1] . "'";
> }
> print "select * from database.table where " . join(" and ",
$sql_query);
> ?>
>
> The output:
>
> select * from database.table where author = 'Jane Smith' and institution =
> 'university of Cambridge' and year = '1976'
> Sandman[.net]
Thank you sandman! That works perfectly. Beer waiting at the Eagle for you!
regards,
brendan.
[Back to original message]
|