100分求解:PHP 中怎么替换不固定的字符串 【在线等】 本帖最后由 roha 于 2010-02-09 17:32:29 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 echo preg_replace('@(<a href=\"/ns\?word=(.*))条相同新闻(>></a></font>)@','$1$3',$html);//把正则中的空间去掉, csdn自己加上去的 补充, preg_replace的第三个参数是你自己的字符串 那个标签就有问题的 <a> 和 <font> 标签用反了$str = <<<str<table cellspacing=0 cellpadding=2> <tr> <td class="text"> <a href="http://news.china.com.cn/rollnews/2010-02/09/content_536553.htm " mon="a=5&pn=6" target=_blank> <span> <b>美国对中国 <font color="#C60A00">礼盒 </font>征 <font color="#C60A00">反倾销 </font>税 </b> </span> </a> <font color=#6f6f6f> <nobr>中国网 2010-2-9 09:40 </nobr> </font> <br> <font size=-1>美国对中国 <font color="#C60A00">礼盒 </font>征 <font color="#C60A00">反倾销 </font>税 据《第一财经日报》 就在中国商务部公布对美白羽肉鸡产品 <font color="#C60A00">反倾销 </font>调查初步裁决之际,美国再度挑起贸易战,对中国产礼物盒以及包装 <font color="#C60A00">丝带 </font>征收高额 <font color="#C60A00">反倾销 </font>税。 美国商务部上周五决定,对中国大陆产的礼物盒以及包装 <font color="#C60A00">丝带 </font>,征收最高超过231%的 <font color="#C60A00">反倾销 </font>税,... </font> </td> </tr> </table> <br> <table cellspacing=0 cellpadding=2> <tr> <td class="text"> <a href="http://www.cnstock.com/index/gdbb/201002/379952.htm " mon="a=5&pn=7" target=_blank> <span> <b>午评:5日均线压力沉重 沪指上攻再遇阻 </b> </span> </a> <font color=#6f6f6f> <nobr>中国证券网 2010-2-9 11:44 </nobr> </font> <br> <font size=-1>美国方面则掐准时间,随即表示对中国内地产的礼物盒以及包装 <font color="#C60A00">丝带 </font>征收最高超过231%的 <font color="#C60A00">反倾销 </font>税。消息一出,...业内人士表示,我国 <font color="#C60A00">礼盒 </font>及 <font color="#C60A00">丝带 </font>的生产地主要是东南沿海,而台湾的大部分生产商也已经搬到内地。一旦征收如此之高的 <font color="#C60A00">反倾销 </font>税,大部分国内出口企业将完全放弃美国市场。 ... </font> <a href="/ns?word=%C0%F1%BA%D0+%CB%BF%B4%F8+%B7%B4%C7%E3%CF%FA+cont:1282492241&cl=1&tn=news&rn=30 "><font color=#008000>3条相同新闻>></a></font> </td> </tr> </table> <br> <table cellspacing=0 cellpadding=2> <tr> <td class="thumbnail"> <a class=r href="http://finance.ifeng.com/news/industry/20100209/1816517.shtml " target=_blank mon="a=4"> <img src="/ni?u=http://img.ifeng.com/tres/finance/upload/images/2010/0209/142739/33_1816517_2db4e5ad03bc35af792214efe1cd00b3.jpg " border=1> </a> </td> <td class="text"> <a href="http://finance.ifeng.com/news/industry/20100209/1816517.shtml " mon="a=5&pn=8" target=_blank> <span> <b>中美贸易摩擦拳脚越打越快 广东 <font color="#C60A00">丝带 </font>出口受创 </b> </span> </a> <font color=#6f6f6f> <nobr>凤凰网 2010-2-9 14:27 </nobr> </font> <br> <font size=-1>虽然美国此次对中国 <font color="#C60A00">礼盒 </font> <font color="#C60A00">丝带 </font> <font color="#C60A00">反倾销 </font>涉案金额不高,但选择在中国对美肉鸡案初裁第二天公布,分析普遍认为其“反制”意味明显。自从去年轮胎案以来,中美之间不仅贸易摩擦不断,... </font> <a href="/ns?word=%C0%F1%BA%D0+%CB%BF%B4%F8+%B7%B4%C7%E3%CF%FA+cont:2403721963&cl=1&tn=news&rn=30 "><font color=#008000>5条相同新闻>></a></font> </td> </tr> </table> <br> <table cellspacing=0 cellpadding=2> <tr> <td class="text"> <a href="http://nf.nfdaily.cn/21cbh/content/2010-02/09/content_9095438.htm " mon="a=5&pn=9" target=_blank> <span> <b>美对华 <font color="#C60A00">礼盒 </font> <font color="#C60A00">丝带 </font>征收 <font color="#C60A00">反倾销 </font>税 贸易摩擦升级 </b> </span> </a> <font color=#6f6f6f> <nobr>南方报业网 2010-2-9 08:18 </nobr> </font> <br> <font size=-1>对中国大陆包装 <font color="#C60A00">丝带 </font>征收 <font color="#C60A00">反倾销 </font>税远高于台湾,并没有道理。 另外据相关人士分析,美国此举一旦付诸实施,中国大陆的礼物盒以及包装 <font color="#C60A00">丝带 </font>可能退出美国市场,但对美国人也没有好处。该相关人士指出,美国企业普遍是到中国进行订单采购礼物盒以及包装 <font color="#C60A00">丝带 </font>,常用于情人节等节日礼品的包装,... </font> </td> </tr> </table> <br>str;echo $str;echo '<hr>';$str = preg_replace('/\<a.*相同新闻.*\<\/font\>/Ui', '', $str);echo $str; 4楼那么细心, 我都没看他html, 直接正则配上收工 ... eregi_replace(" <a href=\"/ns\?word=(.*?)条相同新闻>> </a> </font>",'',$str); 用非贪婪匹配就行了 关于Mysql和gd 库加载问题 mysql数据库无法写入script代码 程序运行的时候为什么会出现乱码? 为什么我的JavaScript检验表单什么反应都没有? 关于正则的一个奇怪现象 时间格式检查函数的问题 怎么合并数组? 谁能编写代码? 一个很奇怪的问题:用不同的域名为什么结果不一样? 我在申请的空间上传了phpmyadmin,配置完后,运行显示:CGI/PHP程序错误: 该脚本不允许执行!请问这怎么办? (祥情请进) 各位大侠 在下利用Linux默认环境里的mailx发邮件没问题 我想输出html的邮件内容 PHP错误simplexml_load_string
$str = <<<str
<table cellspacing=0 cellpadding=2>
<tr>
<td class="text"> <a href="http://news.china.com.cn/rollnews/2010-02/09/content_536553.htm " mon="a=5&pn=6" target=_blank> <span> <b>美国对中国 <font color="#C60A00">礼盒 </font>征 <font color="#C60A00">反倾销 </font>税 </b> </span> </a> <font color=#6f6f6f> <nobr>中国网 2010-2-9 09:40 </nobr> </font> <br> <font size=-1>美国对中国 <font color="#C60A00">礼盒 </font>征 <font color="#C60A00">反倾销 </font>税 据《第一财经日报》 就在中国商务部公布对美白羽肉鸡产品 <font color="#C60A00">反倾销 </font>调查初步裁决之际,美国再度挑起贸易战,对中国产礼物盒以及包装 <font color="#C60A00">丝带 </font>征收高额 <font color="#C60A00">反倾销 </font>税。 美国商务部上周五决定,对中国大陆产的礼物盒以及包装 <font color="#C60A00">丝带 </font>,征收最高超过231%的 <font color="#C60A00">反倾销 </font>税,... </font> </td> </tr> </table> <br>
<table cellspacing=0 cellpadding=2>
<tr>
<td class="text"> <a href="http://www.cnstock.com/index/gdbb/201002/379952.htm " mon="a=5&pn=7" target=_blank> <span> <b>午评:5日均线压力沉重 沪指上攻再遇阻 </b> </span> </a> <font color=#6f6f6f> <nobr>中国证券网 2010-2-9 11:44 </nobr> </font> <br> <font size=-1>美国方面则掐准时间,随即表示对中国内地产的礼物盒以及包装 <font color="#C60A00">丝带 </font>征收最高超过231%的 <font color="#C60A00">反倾销 </font>税。消息一出,...业内人士表示,我国 <font color="#C60A00">礼盒 </font>及 <font color="#C60A00">丝带 </font>的生产地主要是东南沿海,而台湾的大部分生产商也已经搬到内地。一旦征收如此之高的 <font color="#C60A00">反倾销 </font>税,大部分国内出口企业将完全放弃美国市场。 ... </font>
<a href="/ns?word=%C0%F1%BA%D0+%CB%BF%B4%F8+%B7%B4%C7%E3%CF%FA+cont:1282492241&cl=1&tn=news&rn=30 "><font color=#008000>3条相同新闻>></a></font>
</td> </tr> </table> <br>
<table cellspacing=0 cellpadding=2>
<tr> <td class="thumbnail">
<a class=r href="http://finance.ifeng.com/news/industry/20100209/1816517.shtml " target=_blank mon="a=4"> <img src="/ni?u=http://img.ifeng.com/tres/finance/upload/images/2010/0209/142739/33_1816517_2db4e5ad03bc35af792214efe1cd00b3.jpg " border=1> </a>
</td>
<td class="text"> <a href="http://finance.ifeng.com/news/industry/20100209/1816517.shtml " mon="a=5&pn=8" target=_blank> <span> <b>中美贸易摩擦拳脚越打越快 广东 <font color="#C60A00">丝带 </font>出口受创 </b> </span> </a> <font color=#6f6f6f> <nobr>凤凰网 2010-2-9 14:27 </nobr> </font> <br> <font size=-1>虽然美国此次对中国 <font color="#C60A00">礼盒 </font> <font color="#C60A00">丝带 </font> <font color="#C60A00">反倾销 </font>涉案金额不高,但选择在中国对美肉鸡案初裁第二天公布,分析普遍认为其“反制”意味明显。自从去年轮胎案以来,中美之间不仅贸易摩擦不断,... </font>
<a href="/ns?word=%C0%F1%BA%D0+%CB%BF%B4%F8+%B7%B4%C7%E3%CF%FA+cont:2403721963&cl=1&tn=news&rn=30 "><font color=#008000>5条相同新闻>></a></font>
</td> </tr> </table> <br>
<table cellspacing=0 cellpadding=2>
<tr>
<td class="text"> <a href="http://nf.nfdaily.cn/21cbh/content/2010-02/09/content_9095438.htm " mon="a=5&pn=9" target=_blank> <span> <b>美对华 <font color="#C60A00">礼盒 </font> <font color="#C60A00">丝带 </font>征收 <font color="#C60A00">反倾销 </font>税 贸易摩擦升级 </b> </span> </a> <font color=#6f6f6f> <nobr>南方报业网 2010-2-9 08:18 </nobr> </font> <br> <font size=-1>对中国大陆包装 <font color="#C60A00">丝带 </font>征收 <font color="#C60A00">反倾销 </font>税远高于台湾,并没有道理。 另外据相关人士分析,美国此举一旦付诸实施,中国大陆的礼物盒以及包装 <font color="#C60A00">丝带 </font>可能退出美国市场,但对美国人也没有好处。该相关人士指出,美国企业普遍是到中国进行订单采购礼物盒以及包装 <font color="#C60A00">丝带 </font>,常用于情人节等节日礼品的包装,... </font> </td> </tr> </table> <br>
str;echo $str;
echo '<hr>';$str = preg_replace('/\<a.*相同新闻.*\<\/font\>/Ui', '', $str);echo $str;