Re: Reg ex help-Removing extra blank spaces before HTML output
| From: | Steve Edberg | Date: | Wed, 05 Dec 2001 07:49:15 +0000 |
| Subject: | Re: Reg ex help-Removing extra blank spaces before HTML output | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-76656@lists.php.net to get a copy of this message | ||
One way to do it is:
$NewString = ereg_replace('[[:space:]]+', ' ', $String);
There are also ways to do it with preg functions that are slightly more efficient; see the pcre docs. And, the standard (AFAIK) reference book for regular expressions is O'Reilly's 'Mastering Regular Expressions'; a worthwhile purchase.
-steve
At 2:06 AM -0500 12/5/01, Ken wrote:
I want to remove all superfluous blank spaces before I sent my HTML output, to make the output smaller. So I'd like to take $input, replace any number of blank space or newlines that are consecutive and replace them with a single blank. I.e. I will list a blank space as b and a newline as n: If input is: bbbbbTEXTHEREbbbnnnbnMOREbEVENMORE Then output should be: bTEXTHEREbMOREbEVENMORE I imagine this would be handled by a simple regular expression call, but I'm no pro with them yet. Any help? Thanks, Ken kenzo@free-music.com-- +------------------------------------------------------------------------+ | Steve Edberg sbedberg@ucdavis.edu | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | +------------------------------------------------------------------------+ | "Restriction of free thought and free speech is the most dangerous of | | all subversions. It is the one un-American act that could most easily | | defeat us." | | - Supreme Court Justice (1939-1975) William O. Douglas | +------------------------------------------------------------------------+