http://www.tin.org/bin/man.cgi?section=7&topic=regex
<?
//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, 0, 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);
?>