Jump to content

Archived

This topic is now archived and is closed to further replies.

zeroblitzt

Removing excess spaces?

Recommended Posts

Hey all, i'm a total regex beginner (never used it), but someone recommended that I use it. What I need to do with it is remove excess spaces from a string (for my message boards).

So if I were to have, say:
[pre]Hello    Everyone[/pre]

it would shorten it down to
[pre]Hello Everyone[/pre]

I'm not sure how to go about doing it though. Any tips?

Share this post


Link to post
Share on other sites
its very easy ,

(\040)+  -- this is the meta character represent space.. and + sign represent if you want to remove multiple spaces. ;)

Share this post


Link to post
Share on other sites
You can use this little preg_replace:
[code=php]<?php
$string = trim (preg_replace ('`[\s]+`', ' ', $string));
?>[/code]

Hope it helps ;)
Boby

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.