[PHP] regex to remove NL and CR
I am extracting text from a text datatype field of a database. The target text is marked (beginning and end) by html comments that have a known--but not uniform--format. Unfortunately, the web-based interface used to maintain the data inserted hard line breaks in the text. I initially tried removing all NL and CR chars from the string, which has the unanticipated result of removing some spaces between words that had wrapped in the admin interface. Now, I need to remove all NL and CR that occur within a string starting with !- and ending with -. I have no idea where to start, because the NL and CR could also occur in the strings that mark the start and end of the comments. I am very new to regex, but starting to get it. If someone could just give me a push in the right direction. Nothing I have tested in regex coach comes close to matching what I need. Kathleen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] regex to remove NL and CR
I am extracting text from a text datatype field of a database. The target text is marked (beginning and end) by html comments that have a known--but not uniform--format. Unfortunately, the web-based interface used to maintain the data inserted hard line breaks in the text. I initially tried removing all NL and CR chars from the string, which has the unanticipated result of removing some spaces between words that had wrapped in the admin interface. Now, I need to remove all NL and CR that occur within a string starting with !- and ending with -. I have no idea where to start, because the NL and CR could also occur in the strings that mark the start and end of the comments. I am very new to regex, but starting to get it. If someone could just give me a push in the right direction. Nothing I have tested in regex coach comes close to matching what I need. Kathleen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regex to remove NL and CR
Hi, Wednesday, August 18, 2004, 9:09:02 AM, you wrote: KB I am extracting text from a text datatype field of a KB database. The target text is marked (beginning and KB end) by html comments that have a known--but not KB uniform--format. Unfortunately, the web-based KB interface used to maintain the data inserted hard line KB breaks in the text. KB I initially tried removing all NL and CR chars from KB the string, which has the unanticipated result of KB removing some spaces between words that had wrapped in KB the admin interface. KB Now, I need to remove all NL and CR that occur within KB a string starting with !- and ending with -. I KB have no idea where to start, because the NL and CR KB could also occur in the strings that mark the start KB and end of the comments. KB I am very new to regex, but starting to get it. If KB someone could just give me a push in the right KB direction. Nothing I have tested in regex coach comes KB close to matching what I need. KB Kathleen This is probably quicker using a callback function like this: $string = !-- a\nlong\rtest\n\rstring --; echo nl2br(htmlentities($string)); echo 'br'; function replace($str){ return preg_replace('/\n\r|\n|\r/',' ',$str[0]); } $newstring = preg_replace_callback('/!--(.*?)--/s','replace',$string); echo nl2br(htmlentities($newstring)); -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php