...

View Full Version : Help with preg_replace...



Boshi
12-28-2007, 03:05 AM
$line = preg_replace("'\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*.?)'e", "getvar(trim(str_replace('$','','\\1')));",$line);


I want that to replace variables in a string with some predefined values I have, well, apparently this code finds the variable ok, but it also reads one illegal character after it. I thought the code was suppose to break when it finds an illegal character, well it does breaks, but it also includes the illegal character in the result. :mad:

Any way to fix this? Thanks.

Inigoesdr
12-28-2007, 04:45 AM
Move the illegal character in the subpattern outside of it. ie:

$line = preg_replace("'\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*).?'e", "getvar(trim(str_replace('$','','\\1')));",$line);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum