PHP截取并生成纯文本字符串

发布时间:2020-10-08 12:24:14 作者:高万耀
来源:网络 阅读:984

php截取并生成纯文本字符串。最近使用文本编辑器保存的内容中有html,css以及js标记,但是我只想截取前面一部分纯文本内容显示摘要,这里直接上代码,如下:

/**
 * PHP清除html、css、js格式并去除空格的PHP函数,并具有截取UTF-8字符串的作用
 */
function cutstr_html($string, $sublen){
  $string = strip_tags($string);
  $string = preg_replace ('/\n/is', '', $string);
  $string = preg_replace ('/ | /is', '', $string);
  $string = preg_replace ('/ /is', '', $string);

  preg_match_all("/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/", $string, $t_string);   
  if(count($t_string[0]) - 0 > $sublen) $string = join('', array_slice($t_string[0], 0, $sublen))."…";   
  else $string = join('', array_slice($t_string[0], 0, $sublen));

  return $string;
 }

希望对大家有用

PHP截取并生成纯文本字符串PHP截取并生成纯文本字符串

推荐阅读:
  1. PHP字符串分离、截取函数(explod)
  2. php 字符串截取

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php 符串 文本字符串

上一篇:微信小程序picker组件简单用法示例【附demo源码下载】

下一篇:使用jquery模拟a标签的click事件无法实现跳转的解决

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》