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

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

/**
 * 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;
 }

但愿对你们有用css

j_0026.gifj_0018.gif

相关文章
相关标签/搜索