Originally posted by mstringham
Thanks for the explaination ednark I will give them a try -
I thought about using an array - but have read different things regarding the usage of preg and str replace.
Well, as ednark says, if you know the exact string you're trying to replace, str_replace() is perfectly adequate, and a lot faster (and less error-prone, because preg_replace() treats a lot of characters specially) than preg_replace.
Another question I have is regarding the preg_replace -
I have seen expressions with the /\/\/\ in them and $1 or $2 that seem to used as a delimeter of sorts - what's with the funky syntax?
This is covered in the manual pages about preg_* functions (particularly the section on "Pattern Syntax". The /\/\/ you mention is commonly referred to as "falling toothpick syndrome" - since / has a special meaning in regexps, if you really want to say / (in URLs, for example), you have to escape it - and the escape character is a . Of course, that means \ is a special character as well...
As for $1 and $2, those are back references (something that regular expressions aren't really supposed to be capable of - but this is programming, not language theory). If you wrap bits of your pattern in () then you can refer back to the strings those bits match with a $1 etc. (actually, \1 etc., but apparently $1 works as well) and say "... and then a repeat of that bit".
A simple pattern, that finds bits of strings that are doubled up (in this sentence, it would find the double "t" in "pattern"). In the previous paragraph there is a double s, a double m, a double p, a double l, a double ., and in this paragraph there is a deliberate doubling deliberate doubling of the phrase "deliberate doubling":
/(.+)\1/