www.webdeveloper.com
Results 1 to 6 of 6

Thread: preg_replace warning message

  1. #1
    Join Date
    Dec 2004
    Posts
    439

    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?

  2. #2
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,739

  3. #3
    Join Date
    Dec 2004
    Posts
    439
    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?

  4. #4
    Join Date
    Dec 2004
    Posts
    439
    forgive my RE noobness...

    is this correct?

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

  5. #5
    Join Date
    Dec 2004
    Posts
    439
    even this post on php.net show it the way i have ti above

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

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,175
    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
  •  
HTML5 Development Center



Recent Articles