Yeah, didn't realize I was matching the wrong thing. Think I'm all set now.
Another related question. I need to replace "Hello", and I've been using preg_match and preg_replace to do this. I use match to get "Hello" which gets looked up in the database and stored into a string. I then use replace to replace "Hello" with what came from the database.
Is there a better way to do this, say with just preg_replace?
16 Feb, 2010, David Haley wrote in the 4th comment:
Votes: 0
In Lua you can give a custom function for how to handle substitutions, which can avoid the two scans of the string. I don't remember if PHP has a similar function, but it might. Another option would be to match all three components ("[translate=…]", "Hello", "[/translate]") and then construct a new string by concatenating the first and third match with the DB's result in the middle.
I'm trying to match:
And pull out "Hello".
I have:
But it doesn't seem to be matching. I've tried a bunch of different ways and still no go.
[EDIT] Hm, that's why. Apparently I need to be matching:
Do I need to escape the colon? I don't think it's pulling out Hello (matches[0])…