还是一段C代码的运作

imageready 2006-03-04 06:58:51
function clean_summary($strSummary) {
// 把结尾错误截断的HTML标签去掉
$arrMatchings = array(
array("<", ">"),
array("&", ";")
);
foreach ($arrMatchings as $arrMatching) {
$intL = strrpos($strSummary, $arrMatching[0]);
if ($intL !== false) {
$intR = strrpos($strSummary, $arrMatching[1]);
if ($intL > $intR) $strSummary = substr($strSummary, 0, $intL);
}
}
// 为了效率,能用str_replace搞定的就不用正则表达式
$strSummary = str_replace(array(
"<br>", "<br/>", "</font>", "</span>"
), array(
"<br />", "<br />", "", ""
), $strSummary);
// 有些非得用正则表达式,顺便复习一下正则表达式的用法
$arrPatterns = array(
"#<script[.\s]*</script>#is",
"#<script.*/>#is",
"#<iframe[.\s]*</iframe>#is",
"#<iframe.*/>#is",
"#<img([^>]*)([^/])>#is",
'#(height|width)="?(\d+)(px)?"?#is',
"#border=[^\s]* #is",
"#<font[^>]*>#is",
"#<span[^>]*>#is",
"#<div[^>]*></div>#is",
"#<p[^>]*></p>#is"
);
$arrReplacements = array(
"", "", "", "",
"<img\1\2 />",
'\1="\2"',
"", "", "", "", ""
);
$strSummary = preg_replace($arrPatterns, $arrReplacements, $strSummary);
// 找出单独的“&”替换成“&”
$intAnd = -1;
while (($intAnd = strpos($strSummary, "&", $intAnd + 1)) !== false) {
if (($intSemicolon = strpos($strSummary, ";", $intAnd)) !== false) {
if ($intSemicolon - $intAnd > 6) {
$strSummary = substr_replace($strSummary, "&", $intAnd, 1);
continue;
}
$strEntity = substr($strSummary, $intAnd, $intSemicolon - $intAnd + 1);
$arrEntities = array(
" ", "&", "<", ">", """
);
$boolNotEscaped = true;
foreach ($arrEntities as $e) {
if ($strEntity == $e) {
$boolNotEscaped = false;
break;
}
}
if (!$boolNotEscaped) continue;
if (!preg_match("^&#\d+;\$", $strEntity)) {
$strSummary = substr_replace($strSummary, "&", $intAnd, 1);
}
} else $strSummary = substr_replace($strSummary, "&", $intAnd, 1);
}
return $strSummary;
}
...全文
32 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
unionize 2006-03-04
  • 打赏
  • 举报
回复
Mail sent
unionize 2006-03-04
  • 打赏
  • 举报
回复
倒,已发送
Hrunt 2006-03-04
  • 打赏
  • 举报
回复
????
这不是C语言的代码吧~~~

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧