note 8369 added to ereg_replace
| From: | Maxim at php2 dot chek dot com | Date: | Fri, 08 Sep 2000 11:21:08 +0000 |
| Subject: | note 8369 added to ereg_replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-4533@lists.php.net to get a copy of this message | ||
Getting the mess of catacters from your form eh,?
Here's the only thing you need to transform all newlines into it's HTML equivalent, and I
mean it, it will change your point of view on regular expressions!
/* Change them if you know what into */
$br='<BR>'; $p='<P>';
/* Catches almost everything,
* add remove modify it into whatever you think NewLines also are */
$chr="\n\r\015".chr(013).chr(010);
// RegEx:
$out =ereg_replace($br."[ \t\n$br]*".$br, "\n$p",
ereg_replace("[$chr]", "\n$br", $text));
$out =ereg_replace("^[ \t\n$br$p]*($br|$p)|[ \t\n$br$p]*$", '', $out);
/*
* The first line of RegEx finds all NewLines of every shape and type and replaces it with
BR's,
* and then goes replacing two repeating BR's even if between are other BR's or
* characters like spaces, tabs, newlines,
* The second line, will shrink all the text from the top and the bottom deleting whatever is not a
text
*
* That's it! Have fun!
*/
Maxim Maletsky
http://www.php.net/manual/function.ereg-replace.php