...

View Full Version : preg_replace (don't know how to describe it)



xcow
02-24-2007, 03:19 PM
$variable["new"]="hi";
$variable["cow"]="wow";
$string="nice to meet you [phpfile=new]";
$pattern='/\[phpfile=(\w+)\]/i';
$replace=$variable["$1"];
preg_replace($pattern,$replace,$string);


When I tried this, it gave me an error about $1 not existing. Does anyone know how to solve this? I have also tried \\1, and tried heck alot of different things, but couldn't resolve this.

Thanks..

- Mike

Fr0Gs
02-26-2007, 05:15 AM
What is $1

php.net example


$string = 'April 15, 2003';
$pattern = '/(\w+) (\d+), (\d+)/i';
$replacement = '${1}1,$3';
echo preg_replace($pattern, $replacement, $string);

Hopefully this will help you



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum