Home > php教程 > PHP源码 > body text

字符串截取代码

WBOY
Release: 2016-06-08 17:26:25
Original
1231 people have browsed it

下面写了二个php 字符串截取函数,方法很简单,string要截取的字符串,sublen长度,$start开位置哦。

<script>ec(2);</script>
 代码如下 复制代码

 function my_sub_str($string, $sublen, $start)
 {
  $pa = "/fdddd";
  preg_match_all($pa, $string, $t_string);

  if(count($t_string[0]) - $start > $sublen) return join('', array_slice($t_string[0], $start, $sublen))."...";
  return join('', array_slice($t_string[0], $start, $sublen));
 }

 /**
  * 字符串截取 不加"..."
  */

 代码如下 复制代码

 function my_sub_str_00($string, $sublen, $start)
 {
  $pa = "/sss/";
  preg_match_all($pa, $string, $t_string);

  return join('', array_slice($t_string[0], $start, $sublen));
 }

//字符截取测试

 代码如下 复制代码
$string ="www.111cn.net中国web第一站";
echo my_sub_str($string, 10, 0); //输出 www.111cn....
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template