preg_replace warning message
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?
Each member of $patterns needs to contain a complete and valid regex with start and end delimiters. http://www.php.net/pcre
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?
forgive my RE noobness...
is this correct?
$patterns = array('/chr(145)/','/chr(146)/','/chr(147)/','/chr(148)/','/chr(150)/','/chr(151)/');
even this post on php.net show it the way i have ti above
http://www.php.net/manual/en/function.chr.php#61853
You could do something like this:
PHP Code:
$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:
PHP Code:
$search = array
(
'/[\x91\x92]/' ,
'/[\x93\x94]/' ,
'/[\x96\x97]/'
);
$replace = array( "'" , '"' , '-' );
$notes = preg_replace ( $search , $replace , $notes );
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in
Nation
eBookworm.us
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks