note 40950 added to function.substr

From: Date: Wed, 24 Mar 2004 15:30:24 +0000
Subject: note 40950 added to function.substr
Groups: php.notes 
Request: Send a blank email to php-notes+get-67104@lists.php.net to get a copy of this message
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); } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.substr.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+40950 Delete -- http://master.php.net/manage/user-notes.php?action=delete+40950&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+40950&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#67104) next »