String replace
Posted: Thu Aug 24, 2006 9:52 am
I have a string that could contain one or more substrings of the form $(bla). I have several rows of a database in which I need to run against this master string, changing the $(bla) to the value of the bla field for that row in the database, thus producing a series of output URLs.
I'm using this pattern to find the substr: \$\((\w+)\) and I want then to replace it with $row['bla'], with this happening once per row of the database results. But what function can handle this? It seems the regex functions only want strings for the pattern and replacement, so they won't work.
The only thing I can think of is using an array of search and replacements, one for each column in the database and then running it over the string. So I am basically checking every database field on every row, which seems like a lot of work, given that only 1 field or even none may need to be replaced. (See example 2)
Any ideas?
Thanks.
I'm using this pattern to find the substr: \$\((\w+)\) and I want then to replace it with $row['bla'], with this happening once per row of the database results. But what function can handle this? It seems the regex functions only want strings for the pattern and replacement, so they won't work.
The only thing I can think of is using an array of search and replacements, one for each column in the database and then running it over the string. So I am basically checking every database field on every row, which seems like a lot of work, given that only 1 field or even none may need to be replaced. (See example 2)
Any ideas?
Thanks.