Page 1 of 1

Regular expressions

Posted: Thu Feb 08, 2007 7:22 am
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]

Posted: Thu Feb 08, 2007 7:59 am
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.'/';