Click to See Complete Forum and Search --> : preg_replace warning message


decibel
10-25-2006, 04:53 PM
Hello, here the code:

// Trim garbage characters from the detailed descriptions
$patterns = array(chr(145),chr(146),chr(147),chr(148),chr(150),chr(151));
$replacements = array("'","'",'"','"','-','-');
if($notes != ""){
$notes = preg_replace($patterns, $replacements, $notes);
}

Im not the great with reg exp yet, and I am getting this warning message, any ideas why its giving me this message?

Warning: preg_replace() [function.preg-replace]: No ending delimiter '?' found in C:\Program Files\blah\blah\www\admin\import.php on line 148

$notes is user entered data in text field, perhaps im encountering a character that is breaking the reg exp?

bokeh
10-25-2006, 04:58 PM
Each member of $patterns needs to contain a complete and valid regex with start and end delimiters. http://www.php.net/pcre

decibel
10-25-2006, 05:01 PM
This is from an app written by another person in php4, now im working on this app on my local machine in php5, is the diff between 4 and 5 why the warning wasn't issued before, or perhaps it always was there, just the warning level not shown?

decibel
10-25-2006, 05:25 PM
forgive my RE noobness...

is this correct?

$patterns = array('/chr(145)/','/chr(146)/','/chr(147)/','/chr(148)/','/chr(150)/','/chr(151)/');

decibel
10-25-2006, 05:34 PM
even this post on php.net show it the way i have ti above

http://www.php.net/manual/en/function.chr.php#61853

NogDog
10-25-2006, 05:59 PM
You could do something like this:

$search = array
(
'/['.chr(145).chr(146).']/',
'/['.chr(147).chr(148).']/',
'/['.chr(150).chr(151).']/'
);
$replace = array("'", '"', '-');
$notes = preg_replace($search, $replace, $notes);

Possibly you would find it simpler to use the preg hex codes:

$search = array
(
'/[\x91\x92]/',
'/[\x93\x94]/',
'/[\x96\x97]/'
);
$replace = array("'", '"', '-');
$notes = preg_replace($search, $replace, $notes);