<?php
/***********************************************************************/
/*                                                                     */
/*  Author:                                                     */
/*  HomePage: http://www.cnblogs.com/jishui/admin/                                          */
/*  Email: jjhjs166@163.com                                             */
/*  QQ:315429861                                                         */
/*                                                                     */
/***********************************************************************/

function get_substr($string,$start=\’0\’,$length=\’\’)
{
 $start = (int)$start;
 $length = (int)$length;
 $i = 0;
 if(!$string)
 {
  return;
 }
 if($start>=0)
 {
  while($i<$start)
  {
   if(ord($string[$i])>127)
   {
    $i = $i+2;
   }
   else
   {
    $i++;
   }
  }
  $start = $i;
  if($length==\’\’)
  {
   return substr($string,$start);
  } 
  elseif($length>0)
  {
   $end = $start+$length;
   while($i<$end)
   {
    if(ord($string[$i])>127)
    {
     $i = $i+2;
    }
    else
    {
     $i++;
    }
   }
   if($end != $i-1)
   {
    $end = $i;
   }
   else
   {
    $end–;
   }
   $length = $end-$start;
   return substr($string,$start,$length);
  }
  elseif($length==0)
  {
   return;
  }
  else
  {
   $length = strlen($string)-abs($length)-$start;
   return get_substr($string,$start,$length);
  }
 }
 else
 {
  $start = strlen($string)-abs($start);
  return get_substr($string,$start,$length);
 } 
}

?>

版权声明:本文为jishui原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/jishui/articles/1212928.html