Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2008
    Posts
    39
    Thanks
    0
    Thanked 1 Time in 1 Post

    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

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    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.

  • #3
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,307
    Thanks
    4
    Thanked 205 Times in 202 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •