php – rtrim function

Hi, php rtrim function is very similar to chop function

Strip whitespace (or other characters) from the end of a string

example code:
<?php // php code start tag
$text=”test “; // assigning “test ” to variable $text with a space tag at the end “test ”
print rtrim($text); // now we are printing data on page with rtrim function
// output on the screen will be “text” rtrim function remove that space from the end and return that value to print function and print function will display that out put on page
?>//php end code tag
Basically this function is used to remove spaces from the right side just like chop function.

Example rtrim:
This shows how rtrim works when using the optional charlist parameter:
rtrim reads a character, one at a time, from the optional charlist parameter and compares it to the end of the str string. If the characters match, it trims it off and starts over again, looking at the “new” last character in the str string and compares it to the first character in the charlist again. If the characters do not match, it moves to the next character in the charlist parameter comparing once again. It continues until the charlist parameter has been completely processed, one at a time, and the str string no longer contains any matches. The newly “rtrimmed” string is returned.
<?php
// Example 1:
rtrim(‘This is a short short sentence’, ‘short sentence’);
// returns ‘This is a’
// If you were expecting the result to be ‘This is a short ‘,
// then you’re wrong; the exact string, ‘short sentence’,
// isn’t matched.  Remember, character-by-character comparison!
// Example 2:
rtrim(‘This is a short short sentence’, ‘cents’);
// returns ‘This is a short short ‘
?>

Advertisements

3 Comments »

  1. John said

    Thanks for the command. This is what I’m using for http://www.crabzy.com and it works fine and smoothly !
    Great one.
    Rgds

  2. Lee Murray said

    this is exactly what I was looking for. Thankssssssss

  3. amitmondal said

    Nice tutorial….thanks for this post…..
    Please visit this link for learn more script.
    http://amitmondal.wordpress.com/

RSS feed for comments on this post · TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: