/**
* PHP过滤html 正则表达式
*
* @param
* @arrange 512-笔记网: www.512Pic.com
**/
//href替换
function AHREF2text($string) {
return eregi_replace('<A .*HREF=("|')?([^ "']*)("|')?.*>([^<]*)</A>','[\4] (link: \2)',$string);
}
$str = 'A link to <a href="http://www.PHP.net">PHP.net</A>';
$str = AHREF2text($str);
//A link to [PHP.net] (link: http://www.PHP.net)
//url提取
$str = 'A link to <a href="http://www.PHP.net">PHP.net</A>';
$str = 'A link to <a href="<a href="http://www.PHP.net">http://www.PHP.net</a>">PHP.net</A>';
$str = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a href="\0">\0</a>",$str);
//A link to <a href="<a href="http://www.PHP.net">http://www.PHP.net</a>">PHP.net</A>
//汉字截取组合,仍为汉字
$str = "我们";
$str = substr($str,1).substr($str,1,1);
//空格[:space:],具体看PHP.net的POSIX regex
$str = "a b c";
$str = ereg_replace("[[:space:]]",'z',$str);
//对正则表达式结果的应用,\0~9,0代表整个表达式
$str = '<FONT color=#ff0000>fjl</FONT><IMG src="/bx9/bs_edit/adveditor/images/smiley/msn/wink_smile.gif" border=0></FONT>';
$str = ereg_replace("<IMG[^<>]*src="([^[:space:]"]*)"[^<>]*>","\1",$str);
if ( FALSE == strip_tags($str) )
{
return FALSE;
}
echo htmlspecialchars($str);
/*** 来自编程之家 jb51.cc(jb51.cc) ***/
preg_replace("/<.+?>/i","",$str); //替换所有HTML的标识