Here's the problem. You get a whitespace delimited string of search terms, that need to be transformed into the WHERE clause of an SQL statement. Each term must appear in either of two fields (or in both). For 2 terms the desired SQL is:
(field1 LIKE '%term1%' OR field2 LIKE '%term1%') AND (field1 LIKE '%term2%' OR field2 LIKE '%term2%')
In Perl this is easy using a combined split-map-join operation and requires no intermediate variables. In PHP it feels really clumsy, needing me to create a second array and use multiple statements.
Both of my example code segments take a string argument $search and spit out the SQL into $terms.
Perl:
PHP:
How can the PHP version be improved?
Please don't reply unless you've got something to say about this example. I don't care how much better you think Perl/PHP is.
Just a thought
[edit]forgot my sig![/edit]
[ April 18, 2001 07:47 AM: Message edited by: cal ]