[nycphp-talk] dynamic string manipulation when web serving -, best practices and ideas?
Jayesh Sheth
jayeshsh at ceruleansky.com
Fri Jun 11 12:41:24 EDT 2004
Hello,
I would say that the easiest way to do this would be to use (the
built-in PHP function) str_replace() after you have run the query.
For example, suppose you have the following table:
id | title | desc
---|-------|-----
1 | bob | nickname
Your goal is to replace "bob" with "Robert" when it appears in the title
field.
So, a PHP function runs the following query:
SELECT title FROM mytable WHERE id='1'
[...]
Then , you do something like:
$title = str_replace("bob", "Robert", $title);
Later, if you want "bob" to be replaced with "Roberta", you could just do:
$title = str_replace("bob", "Roberta", $title);
I know my answer seems a bit simplistic; I hope I understood the nature
of your question correctly - perhaps their are more complex replacement
that you'd like to do.
In any case, PHP has more than enough search and replace features - so I
would do the replacement from within PHP (and not in the SQL query or
elsewhere).
Best Regards,
- Jay
More information about the talk
mailing list