note 8369 deleted from function.ereg-replace by jimw

From: Date: Fri, 02 Nov 2001 01:50:17 +0000
Subject: note 8369 deleted from function.ereg-replace by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-20193@lists.php.net to get a copy of this message
[Editor's note: See the nl2br() function, is simpler than this approach, but the approach below can be used for other tag conversions] 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

« previous php.notes (#20193) next »