Page 1 of 1

preg_replace question

Posted: Tue Nov 26, 2002 4:12 pm
by rxsid
Hi all,
I'm trying to replace a string with the beginning part of a url such as:
Replace: word
With: http://www.asite.com/adirectory
I've tried this many way...with no success yet:

Code: Select all

$xyz = preg_replace("word", "http://www.asite.com/adirectory", $aStringReadIn);

also tried:
$xyz = preg_replace("/word/", "http://www.asite.com/adirectory", $aStringReadIn);

and:
$xyz = preg_replace("word", "'http://www.asite.com/adirectory'", $aStringReadIn);
I keep getting this error:
Warning: Delimiter must not be alphanumeric or backslash

What do I need to do to fix this?

Thanks,
rxsid

Posted: Tue Nov 26, 2002 4:30 pm
by BigE
Well, first you need to learn a little bit about PCRE php.net/pcre and second, you could probably just use str_replace() php.net/str_replace if your just looking to replace a word in the variable. REGEX is more for complex match and replace. I suggest you also check out the strings section of the manual php.net/strings Hope that helps.