note 89747 added to function.substr
| From: | link at osu1 dot php dot net | Date: | Sat, 21 Mar 2009 03:19:57 +0000 |
| Subject: | note 89747 added to function.substr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-152247@lists.php.net to get a copy of this message | ||
I created some functions for entity-safe splitting+lengthcounting:
<?php
function strlen_entities($text)
{
preg_match_all(
'/((?:&(?:#[0-9]{2,}|[a-z]{2,});)|(?:[^&])|'.
'(?:&(?!\w;)))s',$text,$textarray);
return count($textarray[0]);
}
function substr_entities($text,$start,$limit=0)
{
$return = '';
preg_match_all(
'/((?:&(?:#[0-9]{2,}|[a-z]{2,});)|(?:[^&])|'.
'(?:&(?!\w;)))s',$text,$textarray);
$textarray = $textarray[0];
$numchars = count($textarray)-1;
if ($start>=$numchars)
return false;
if ($start<0)
{
$start = ($numchars)+$start+1;
}
if ($start>=0)
{
if ($limit==0)
{
$end=$numchars;
}
elseif ($limit>0)
{
$end = $start+($limit-1);
}
else
{
$end = ($numchars)+$limit;
}
for ($i=$start;$i<=$end;$i++)
{
$return .= $textarray[$i];
}
return $return;
}
}
?>
----
Server IP: 83.137.20.135
Probable Submitter: 84.25.235.231
----
Manual Page -- http://www.php.net/manual/en/function.substr.php
Edit -- https://master.php.net/note/edit/89747
Del: integrated -- https://master.php.net/note/delete/89747/integrated
Del: useless -- https://master.php.net/note/delete/89747/useless
Del: bad code -- https://master.php.net/note/delete/89747/bad+code
Del: spam -- https://master.php.net/note/delete/89747/spam
Del: non-english -- https://master.php.net/note/delete/89747/non-english
Del: in docs -- https://master.php.net/note/delete/89747/in+docs
Del: other reasons-- https://master.php.net/note/delete/89747
Reject -- https://master.php.net/note/reject/89747
Search -- https://master.php.net/manage/user-notes.php