note 31637 added to function.chop
| From: | thebitman at attbi dot com | Date: | Mon, 28 Apr 2003 21:24:07 +0000 |
| Subject: | note 31637 added to function.chop | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-47223@lists.php.net to get a copy of this message | ||
Actually, PHP's chop() acts just as perl's chomp(). The above user-contributed example
does not act enough like perl's chop(), however. An important part of perl's chop() is
that it returns the chop()ed character. Here's how to get perl-style chop()s [let's call
it chomp() just to bring this whole mess full-circle]
function chomp(&$string)
{
if (is_array($string))
{
foreach($string as $i => $val)
{
$endchar = chomp($string[$i]);
}
} else {
$endchar = substr("$string", strlen("$string") - 1, 1);
$string = substr("$string", 0, -1);
}
return $endchar;
}
--
http://www.php.net/manual/en/function.chop.php
http://master.php.net/manage/user-notes.php?action=edit+31637
http://master.php.net/manage/user-notes.php?action=delete+31637
http://master.php.net/manage/user-notes.php?action=reject+31637