TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Script Giveaway (http://www.talkphp.com/script-giveaway/)
-   -   Trimming Whitespace (http://www.talkphp.com/script-giveaway/2592-trimming-whitespace.html)

mortisimus 04-06-2008 10:00 AM

Trimming Whitespace
 
Just a very small function for you, if you wish to replace spaces in a variable, use this function. The good this about it is that it does not matter how much whitespace there is, it will convert it to an _

PHP Code:

function removeSpace($input){
    echo 
preg_replace("/(\s)+/""_"$input);



Orc 04-06-2008 10:54 AM

The underlines remind me of some MOD_REWRITE urls. Haha

e.g. HTTP://WWW.EXAMPLE.COM/BLOG/MY_FIRST_ENTRY/

sketchMedia 04-06-2008 02:08 PM

why not use
PHP Code:

str_replace(' ''_'$string); 

just wondering

delayedinsanity 04-06-2008 02:39 PM

Depends on what result you prefer. The original method will take any amount of spaces in a row and replace them with a single underscore. The second method would return one underscore for every space it found.
-m

Kalle 07-01-2008 07:39 AM

Quote:

Originally Posted by sketchMedia (Post 13248)
why not use
PHP Code:

str_replace(' ''_'$string); 

just wondering

A whitespace in PCRE may also be a tab, newline, carrige return ect. as far as I remember =)

</stupid-bump>

sketchMedia 07-10-2008 10:05 AM

Quote:

A whitespace in PCRE may also be a tab, newline, carrige return ect. as far as I remember =)
good point, i hadn't thought of that.


All times are GMT. The time now is 06:54 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0