将html转换为纯文本:有时候可能需要将html文本转换为纯文本,可以使用strip_tags()函数达到这个目的,该函数删除字符串中的所有html和php标记,只剩下文本实体,其形式为:
string strip_tags(string str[,string allowable_tags])
可选的参数allowable_tags指定在此过程中可以跳过的标记,下面的例子使用了strip_tags()删除字符串中的所以html标记,代码如下:
$input = email example@example.com; echo strip_tags($input); 这回返回以下结果:email example@example.com下面的例子删除标记之外的所有标记:$input = this example is yanshare!; echo strip_tags($input, ); //返回结果如下: this example is yanshare! php版将html中的
换行符转换为文本框中的换行符,代码如下:function br2nl($text){ return preg_replace('//i','',$text); } //或者: function br2nl($text){ $text=preg_replace('//i',chr(13),$text); return preg_replace('/ /i',' ',$text); }
代码如下:
chr(161),
chr(162),
chr(163),
chr(169),
chr(1));
$text = preg_replace ($search, $replace, $document);
使用上面这个方法也可以实现将简答的html代码转换为txt文本.
本文链接:
收藏随意^^请保留教程地址.
