//纯文本输出
/**纯文本输出
* @param $string 字符串
* @param $len 截取长度
*/
public function fromat_html($string,$len){
$string ="<p style=\"font-family: Simsun; font-size: 14px; line-height: 21px; white-space: normal;\">人情如风,有冷有暖,情难舍,轻落,一点一点消融,</p><p style=\"font-family: Simsun; font-size: 14px; line-height: 21px; white-space: normal;\"> <a href=\"http://www.duwenzhang.com/huati/shengming/index1.html\" style=\"color: rgb(51, 51, 51); text-decoration: none;\">生命</a>如席,有酸有甜,心难留,遥望,一丝一丝<a href=\"http://www.duwenzhang.com/huati/xintong/index1.html\" style=\"color: rgb(51, 51, 51); text-decoration: none;\">心痛</a>,</p><p style=\"font-family: Simsun; font-size: 14px; line-height: 21px; white-space: normal;\"> 走得太急,脚累,要求太高,难免就会失落</p><p style=\"font-family: Simsun; font-size: 14px; line-height: 21px; white-space: normal;\"> 想得太多,心累,<a href=\"http://www.duwenzhang.com/huati/zhuiqiu/index1.html\" style=\"color: rgb(51, 51, 51); text-decoration: none;\">追求</a>太多,难免不知所措,</p><p style=\"font-family: Simsun; font-size: 14px; line-height: 21px; white-space: normal;\"> 没有<a href=\"http://www.duwenzhang.com/huati/shiyan/index1.html\" style=\"color: rgb(51, 51, 51); text-decoration: none;\">誓言</a>,脉脉相连,生命就多了一份别样的<a href=\"http://www.duwenzhang.com/huati/sinian/index1.html\" style=\"color: rgb(51, 51, 51); text-decoration: none;\">思念</a>,</p><p style=\"font-family: Simsun; font-size: 14px; line-height: 21px; white-space: normal;\"> 两两相望,天涯相伴,<a href=\"http://www.duwenzhang.com/wenzhang/renshengzheli/\" style=\"color: rgb(51, 51, 51); text-decoration: none;\">人生</a>不就是若远若近的距离,</p><p style=\"font-family: Simsun; font-size: 14px; line-height: 21px; white-space: normal;\"> </p>";
$string= preg_replace('/(style=".*?")/','', $string);
$string= preg_replace('/(id=".*?")/','', $string);
$string= preg_replace("/<style.*?style>/is","",$string);
$string= preg_replace("/<a.*?a>/is","",$string);
$string= preg_replace("/[p|P]/","",$string);
$string= preg_replace("/[<|>]/","",$string);
$string= preg_replace("/\//","",$string);
$string= preg_replace("/\s/","",$string);
$string= preg_replace("/\n\r/","",$string);
$string= preg_replace("/\t/","",$string);
$string= preg_replace("/ /","",$string);
$string= preg_replace('/<string(src="|alt=")/',"<string $1",$string);
$string= preg_replace('/<a(href=")/',"<a $1",$string);
return mb_substr($string, 0, $len, 'utf-8');
}
php 纯文本输出html
猜你喜欢
转载自blog.csdn.net/helloworld_dream/article/details/80763345
今日推荐
周排行