求一个简单的php正则表达式, 200分

xiaodao2008 2009-05-13 07:57:19
<!--XXXXXXX-->
网页中有许多这样的代码段,现在需要把这个代码段直接移除。请问如何写?在线等

比如可能存在如下内容:
<p><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning /> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><!--[if !mso]><span class="mceItemObject" classid="clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D" id=ieooui></span><br />
<mce:style><! st1\:*{behavior:url(#ieooui) } --></p>
<p><!--[endif]--> <!--[if gte mso 10]><br />
<mce:style><! /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} --></p>
<p><!--[endif]--></p>
...全文
101 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
jeremyadison 2009-05-14
  • 打赏
  • 举报
回复
$tmp = "/(<!--[ \t\r\n]*([^<]*))|(-->)/";
echo $result = preg_replace($tmp,"",$strString);
exit;
caffeewithcoke 2009-05-14
  • 打赏
  • 举报
回复
顶起来
xuzuning 2009-05-14
  • 打赏
  • 举报
回复
你是要删除形如 <!--[if gte mso 9]> 的部分
还是要删除形如 <!--[if gte mso 9]> ..... <!--[endif]--> 的部分
gzqhxin 2009-05-13
  • 打赏
  • 举报
回复
应该不难吧,直接把这段字符替换掉就可以了
<?php
$string = "$content";//文件的内容
$pattern = "/<p> <!--\[if gte mso 9\]> (.*)<p> <!--\[endif\]--> </p>/i";//匹配的内容
$replacement = "";//替换的内容
print preg_replace($pattern, $replacement, $string);

?>
jeremyadison 2009-05-13
  • 打赏
  • 举报
回复
严格匹配 <!--XXXXXXX--> 这段?
kloze11 2009-05-13
  • 打赏
  • 举报
回复
这还简单。。老兄你想多了吧。
建议你一个个罗列清楚想要匹配字符

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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