Thursday, 25 September 2014

chop in PHP

PHP chop() function is utilized to remove whitespace or other predefined character from trailing (right hand side)of a string.
It’s an alias to rtrim() function.

Syntax:

chop(string,charlist)
 
Parameters Description:
 
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" -  a tab
  • "\n" -  a new line
  • "\x0B" - a vertical tab.
  • "\r" -  a carriage return
  • " " -  an ordinary white space

Example:

<?php
echo "<strong>chop() function to remove characters from the right side of a string :<strong><br />";
$str = "Good Morning!\n\n";
echo $str;
echo chop($str);
?>

Browser Output  will be:

chop() function to remove characters from the right side of a string :
<html>
<body>
Good Morning!

Good Morning!
</body>
</html>

Output  will be:

Good Morning! Good Morning!

0 comments:

Post a Comment