Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-15-2012, 02:06 PM   PM User | #1
golffor1
New Coder

 
Join Date: Feb 2008
Posts: 39
Thanks: 0
Thanked 1 Time in 1 Post
golffor1 is an unknown quantity at this point
rtrim() and ltrim()

I understand that rtrim() strips all of the white spaces from the end of a string, and ltrim() strips all of the white spaces from the beginning of a string. But if there are white spaces in the middle of a string will it strip them also? I don't want this to happen....

Would you use the functions like this:

PHP Code:

$myvariable 
$rtrim($myvariable);
$anotherVar $ltrim($anotherVar);

echo 
$myvariable;
echo 
$anotherVar
golffor1 is offline   Reply With Quote
Old 09-15-2012, 02:41 PM   PM User | #2
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Quote:
Originally Posted by golffor1 View Post
But if there are white spaces in the middle of a string will it strip them also?
Nope, and the manual pages are pretty explicit about this.
Quote:
Originally Posted by golffor1 View Post
Would you use the functions like this:
No, it would look like this:
PHP Code:

$myvariable 
rtrim($myvariable);
$anotherVar ltrim($anotherVar);

echo 
$myvariable;
echo 
$anotherVar
[/QUOTE]
The $ character denotes a variable and the *trims are functions.
Inigoesdr is offline   Reply With Quote
Old 09-15-2012, 07:11 PM   PM User | #3
djm0219
Senior Coder

 
djm0219's Avatar
 
Join Date: Aug 2003
Location: Wake Forest, North Carolina
Posts: 1,227
Thanks: 2
Thanked 189 Times in 187 Posts
djm0219 is on a distinguished road
And if you want to strip both leading and trailing white space there's plain old trim.

PHP Code:
$myvariable trim($myvariable); 
__________________
Dave .... HostMonster for all of your hosting needs
djm0219 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:52 PM.


Advertisement
Log in to turn off these ads.