note 40950 deleted from function.substr by nlopess
| From: | nlopess@php.net | Date: | Wed, 24 Mar 2004 15:42:57 +0000 |
| Subject: | note 40950 deleted from function.substr by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-67105@lists.php.net to get a copy of this message | ||
Note Submitter:
----
I wrote a little function for removing chars from the end of a string. It works on arrays ass well.
You can even specify how many chars that should be removed from each element, so that three chars
are removed from $array[0] and four from $array[1].
<?php function remove_chars(&$subject, $number){
if(is_array($subject)){
if(is_array($number)){
for($i = 0; $i < sizeof($subject); $i++){
if(isset($number[$i])){
$subject[$i] = substr($subject[$i], 0, strlen($subject[$i]) - $number[$i]);
}else{
$subject[$i] = substr($subject[$i], 0, strlen($subject[$i]) - $number[sizeof($number) - 1]);
}
}
}else{
for($i = 0; $i < sizeof($subject); $i++){
$subject[$i] = substr($subject[$i], 0, strlen($subject[$i]) - $number);
}
}
}else{
$subject = substr($subject, 0, strlen($subject) - $number);
}
}
?>