RE: [PHP] Whitespace filter
| From: | John Coggeshall | Date: | Sat, 06 Dec 2003 02:14:35 +0000 |
| Subject: | RE: [PHP] Whitespace filter | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-172043@lists.php.net to get a copy of this message | ||
You can also use the tidy extension.
http://pecl.php.net/package-info.php?package=tidy
John
On Fri, 2003-12-05 at 20:23, Chris W. Parker wrote:
> Justin Hendrickson <mailto:cricket@djcricket.com>
> 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/
--
-=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=-
John Coggeshall http://www.coggeshall.org/
The PHP Developer's Handbook http://www.php-handbook.com/
-=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=--=~=-