Justin Hendrickson <mailto:[EMAIL PROTECTED]> on Friday, December 05, 2003 5:51 AM said:
> Does anyone have an eloquent way to strip redundant whitespace without > harming whitespace inside <pre>, <textarea> or <script> tags? I'd like > to post-filter my HTML before returning it to the client and I'm not > all that great with regular expressions. If it's just white space on the ends of the text you can use trim(). As for a regular expression... /\s{2,}|\t/ / Will replace 2 or more whitespace characters (tab, space) with just one space as well as replacing one tab character \t with one space. That works in Perl (me thinks), but you'll have to fenagle it to work with ereg_replace() in PHP. Note, thiw will also rip through <pre>, <textarea>, and any other tag. It will apply to the entire string you supply it with. Unless you have gobs of white space in your HTML there's really no point in getting rid of it since all browsers will only display one space even if they encounter multiple spaces. For example: HTML: This is my HTML. Will display as... This is my HTML. ...in any browser. Chris. p.s. My regex is fairly weak so there could very well be a better one for this. -- Don't like reformatting your Outlook replies? Now there's relief! http://home.in.tum.de/~jain/software/outlook-quotefix/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php