preg_replace question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rxsid
Forum Commoner
Posts: 82
Joined: Thu Aug 29, 2002 12:04 am

preg_replace question

Post 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
User avatar
BigE
Site Admin
Posts: 139
Joined: Fri Apr 19, 2002 9:49 am
Location: Missouri, USA
Contact:

Post 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.
Post Reply