CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   rtrim() and ltrim() (http://www.codingforums.com/showthread.php?t=273202)

golffor1 09-15-2012 02:06 PM

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


Inigoesdr 09-15-2012 02:41 PM

Quote:

Originally Posted by golffor1 (Post 1270190)
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 (Post 1270190)
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.

djm0219 09-15-2012 07:11 PM

And if you want to strip both leading and trailing white space there's plain old trim.

PHP Code:

$myvariable trim($myvariable); 



All times are GMT +1. The time now is 01:48 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.