Thursday, January 25, 2007

php - chop function

chop

(PHP 3, PHP 4, PHP 5)
chop -- Alias of rtrim()
Description

This function is an alias of: rtrim().

Note: chop() is different than the Perl chop() function, which removes the last character in the string.

Example 1:
To get a perl style chop():
<?php
$foo = "bar";
$foo = substr("$foo", 0, -1);
echo $foo;

//returns "ba" (removes last character)
?>

Example 2:
<?php
$str = "i am best !\n\n";
echo $str; // displaying value before chop function
echo chop($str); // displaying value with chop
function
?>

Out Put Will Be :(HTML)
<html<
<body<
i am best !

i am best !</body<
</html<
In the above example chop function has removed "\n\n"

Page Out Put Will Be : i am best !i am best !