note 47025 deleted from function.substr by aidan
| From: | aidan@php.net | Date: | Tue, 18 Jan 2005 15:41:02 +0000 |
| Subject: | note 47025 deleted from function.substr by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-83561@lists.php.net to get a copy of this message | ||
Note Submitter: looka
----
here 's the little modification, if we want to shorten string and the string may contain
special shars (e.g. ")
function specsubstr($str, $st = 0, $end = false) {
$d = strlen($str);
//start string
if ($st < 0) $st = $d + $st;
//end string
if (!$end) $end = $d;
elseif($end < 0) $end = $d + $st;
//if end < st then change.
if ($st >= $end) {
$i = $st;
$st = $end;
$end = $i;
}
preg_match_all('/(&.*;)|./u', $str, $ar);
return join('',array_slice($ar[0],$st,$end));
}