Regular expressions

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
mevets
Forum Newbie
Posts: 23
Joined: Fri Sep 15, 2006 10:06 am

Regular expressions

Post by mevets »

I am trying to replace the fist occurance of a string in string2. I am trying to use preg_replace.

Code: Select all

$repThis = "x" .  $currX . " y" . $currY;
$repWith = "xp$repWithX yp$repWithY";
		
$test = preg_replace($repThis, $repWith, $test, 1);
I want to be able to replace a string but I also want to be able to use vars within my pattern. How can this be done?[/s]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

pc regular expressions have to have a delimiter character before and after the pattern. Try

Code: Select all

$repThis = '/x' .  $currX . " y" . $currY.'/';
Post Reply