note 32655 deleted from function.chop by danbrown
| From: | danbrown@php.net | Date: | Mon, 18 May 2009 13:08:54 +0000 |
| Subject: | note 32655 deleted from function.chop by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155670@lists.php.net to get a copy of this message | ||
Note Submitter: zebadger@excite(dhot)com
----
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;
}
?>