最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php截取html字符串自动补全html标签
时间:2022-06-24 18:09:59 编辑:袖梨 来源:一聚教程网
| 代码如下 | 复制代码 |
|
/** $contents = preg_split("~(<[^>]+?>)~si",$html, -1,PREG_SPLIT_NO_EMPTY| PREG_SPLIT_DELIM_CAPTURE); } /** if(strtolower($charset) == 'utf-8') { return $strcut.$dot; /** |
|
实例
| 代码如下 | 复制代码 |
|
* @param 要截取的HTML $str if(ord($str[$i])>128) if ($str[$i+1]=='/') for(;$i<$leng;$i++) |
|
PHP截取字符串,生成文章摘要
我们在写BLOG时经常需要显示文章前一部分,但是又怕不恰当截断破坏封闭标签以造成整个文档结构破坏
| 代码如下 | 复制代码 |
| function text_zhaiyao($text,$length){ //文章摘要生成函数 $test:内容 $length:摘要长度 global $Briefing_Length; mb_regex_encoding("UTF-8"); if(mb_strlen($text) <= $length ) return $text; $Foremost = mb_substr($text, 0, $length); $re = "<(/?) (P|DIV|H1|H2|H3|H4|H5|H6|ADDRESS|PRE|TABLE|TR|TD|TH|INPUT|SELECT|TEXTAREA|OBJECT|A|UL|OL|LI| BASE|META|LINK|HR|BR|PARAM|IMG|AREA|INPUT|SPAN)[^>]*(>?)"; $Single = "/BASE|META|LINK|HR|BR|PARAM|IMG|AREA|INPUT|BR/i"; $Stack = array(); $posStack = array(); mb_ereg_search_init($Foremost, $re, 'i'); while($pos = mb_ereg_search_pos()){ $match = mb_ereg_search_getregs(); /* [Child-matching Formulation]: $matche[1] : A "/" charactor indicating whether current "<...>" Friction is Closing Part $matche[2] : Element Name. $matche[3] : Right > of a "<...>" Friction */ if($match[1]==""){ $Elem = $match[2]; if(mb_eregi($Single, $Elem) && $match[3] !=""){ continue; } |
|
相关文章
- jm天堂网页版官方登录入口-jm天堂网页版直接登录入口 12-14
- 蝉妈妈网页版直达入口-蝉妈妈app官方正版入口在哪 12-14
- 豆包AI智能在线网页解析神器-豆包AI智能在线会议纪要生成助手 12-14
- 小红书Web官网登录入口-小红书官方网页版一键登录 12-14
- 苍云阅读app如何快速找到目录-目录入口位置 12-14
- 苹果ID登录官网入口 - 苹果Apple ID账户登录页面一键直达 12-14