Monday, 29 September 2014

rtrim in PHP

PHP rtrim() function is used to stripe white spaces or other predefined characters from the right side of the string.

Syntax:

rtrim(string,charlist)
string : Required. Defines the input string

charlist : Optional. Indicates which character to remove.

If not then  all of the following characters will be removed:

"\0" – NULL
"\t" – tab
"\n" – new line
"\x0B" – vertical tab
"\r" – carriage return
" " – ordinary white space
Example:

<?php
$str_name = "Today is Monday.\n\n";
echo "Without rtrim : ". $str_name;
echo "<br />";
echo "With rtrim : ". rtrim($str_name);
?>
Output will be:
Without rtrim : Today is Monday.
With rtrim : Today is Monday.
If You Select "View Source" in the browser window, you will see the following HTML :

<html>
<body>
Without rtrim : Today is Monday.

<br />With rtrim : Today is Monday
</body>
</html>

0 comments:

Post a Comment