note 49098 deleted from function.preg-replace by tularis
| From: | tularis@php.net | Date: | Sun, 18 Jun 2006 13:22:54 +0000 |
| Subject: | note 49098 deleted from function.preg-replace by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-114333@lists.php.net to get a copy of this message | ||
Note Submitter: jason at thinkingman dot org
----
A follow-up to my previous posting on removing whitespace using preg_replace().
If you're just interested in removing SPACE characters only, keeping all \n or \r\n -- then try
the following:
<?
$str = preg_replace("/([ ]+)?(\<.+\>)([ ]+)?/", "$2",
ob_get_contents());
?>
Your HTML will format as if a TRIM() method was called on each line.
<html>
<head>
<title>My Fantastic Website! </title>
</head>
<body>
<?=$str?>
</body>
</html>
will output as:
<html>
<head>
<title>My Fantastic Website! </title>
</head>
<body>
This is some text
</body>
</html>
Jason