PHP中的字符串截取自定义函数
2008-02-15 18:19:02 来源:WEB开发网核心提示:if($start < 0) {$start += $end; }if($start > 0) { $s = substr($str,0,$start); if($s[strlen($s)-1] >
if($start < 0)
{
$start += $end;
}
if($start > 0)
{
$s = substr($str,0,$start);
if($s[strlen($s)-1] > $ch)
{
$s = preg_replace($p,$r,$s);
$start += strlen($s);
}
}
$s = substr($str,$start,$end);
$end = strlen($s);
if($s[$end-1] > $ch)
{
$s = preg_replace($p,$r,$s);
$end += strlen($s);
}
return substr($str,$start,$end);
}
function m_substr($str,$start)
{
preg_match_all("/[x80-xff]?./",$str,$ar);
if(func_num_args() >= 3)
{
$end = func_get_arg(2);
return join("",array_slice($ar[0],$start,$end));
}
else
{
return join("",array_slice($ar[0],$start));
}
}
?>
更多精彩
赞助商链接