note 32655 modified in function.chop by vrana
| From: | vrana@php.net | Date: | Tue, 17 Aug 2004 14:54:28 +0000 |
| Subject: | note 32655 modified in function.chop by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-79898@lists.php.net to get a copy of this message | ||
The perl version of chomp only removes newlines. I modified the previous code to do that.
<?php
function chomp(&$string)
{
if (is_array($string))
{
foreach($string as $i => $val)
{
$endchar = chomp($string[$i]);
}
} else {
$endchar = substr("$string", strlen("$string") - 1, 1);
if ($endchar == "\n")
{
$string = substr("$string", 0, -1);
}
}
return $endchar;
}
?>
--was--
The perl version of chomp only removes newlines. I modified the previous code to do that.
function chomp(&$string)
{
if (is_array($string))
{
foreach($string as $i => $val)
{
$endchar = chomp($string[$i]);
}
} else {
$endchar = substr("$string", strlen("$string") - 1, 1);
if ($endchar == "\n")
{
$string = substr("$string", 0, -1);
}
}
return $endchar;
}
http://php.net/manual/en/function.chop.php