求正则表达式 替换字符串中的 width="325325" 为 width="216"的正则表达式 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $str='width="325325"';preg_replace("(\d+)", "216", $str);或者$str='width="325325"';str_replace("325325", "216", $str); :) 不是这个意思我要用preg_replace替换已知字符串中所有的width="????" 为width="216" 写成这样,但是不对!不知道原因$str=preg_replace('(width=\"*\")','width="260"',$str) $str=preg_replace('(width=\"\d+\")','width="260"',$str); $str=preg_replace('(width=\"\d+\")','width="260"',$str);不行啊,运行了,没有匹配到 我试过,完全可以$str='wqdqw qdqwdqd width="325325" qwdqwdqwdqw';$str=preg_replace('(width=\"\d+\")','width="260"',$str);echo $str;要不你把你整个$str贴出来我看看 测试例子,没有成功.$str='<align="middle" height="360" width="480">';$str=preg_replace('(width=\"\d+\")','width="260"',$str); 可是...明明成功了呀...$str=' <align="middle" height="360" width="480">';$str=preg_replace('(width=\"\d+\")','width="260"',$str);echo htmlspecialchars($str); 或者不用htmlspecialchars, 直接查看源代码也行,确实是成功了. 那就奇怪了,我是在帝国cms里面写的bqr[newstext]中含有width="480"<?$str=preg_replace('(width=\"\d+\")','width="260"',$bqr[newstext]);$str=preg_replace('(height=\"\d+\")','height="216"',$str);?><?=$str?>一直没有成功 <object class="OBJECT" id="MediaPlayer" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" width="480" height="360" align="middle"><param name="AUTOSTART" value="false" /><param name="ShowStatusBar" value="-1" /><param name="Filename" value="/d/file/shipindianbo/2009-10-15/64a2790d9392db0fe4fc24206af3205b.wmv" /><embed width="480" height="360" type="application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" src="/d/file/shipindianbo/2009-10-15/64a2790d9392db0fe4fc24206af3205b.wmv" flename="mp"></embed></object> 这我就不清楚了``那个$bqr[newstext]是不是需要转换一下字符格式之类的? 直接$str='<object class="OBJECT" id="MediaPlayer" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" width="480" height="360" align="middle"><param name="AUTOSTART" value="false" /><param name="ShowStatusBar" value="-1" /><param name="Filename" value="/d/file/shipindianbo/2009-10-15/64a2790d9392db0fe4fc24206af3205b.wmv" /> <embed width="480" height="360" type="application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" src="/d/file/shipindianbo/2009-10-15/64a2790d9392db0fe4fc24206af3205b.wmv" flename="mp"> </embed> </object>';$str=preg_replace('(width=\"\d+\")','width="200"',$str);echo htmlspecialchars($str); 都是可以的... 郁闷,单独写个test确实是替换了,在帝国里就是木有替换!!!!!!!!!!<?$str='<object class="OBJECT" id="MediaPlayer" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" width="480" height="360" align="middle"> <param name="AUTOSTART" value="false" /> <param name="ShowStatusBar" value="-1" /> <param name="Filename" value="/d/file/shipindianbo/2009-10-15/64a2790d9392db0fe4fc24206af3205b.wmv" /> <embed width="480" height="360" type="application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" src="/d/file/shipindianbo/2009-10-15/64a2790d9392db0fe4fc24206af3205b.wmv" flename="mp"> </embed> </object>';$str=preg_replace('(width=\"\d+\")','width="260"',$str);$str=preg_replace('(height=\"\d+\")','height="216"',$str);?><?=$str?> 呃..爱莫能助了...把那个$bqr[newstext]转换下行吗?用htmlspecialchars之类的`然后正则`然后再转回来???我也不懂了...祝你好运吧 csv文件导入mysql是否需要新建表呢 关于ignore_user_abort PHP与js的交互问题! 散分,邀朋。合作设计与开发 请教数组算法问题 WEB应用数据保密和安全讨论 求SilverStripe中文资料或Dome PHP是不是单引号和双引号没什么区别呀? 如何将一段中文按照一定的长度分割成小段 下面代码正确的应该怎么写 高手看看,控件捕捉的问题 大家过来帮忙看看我的程序写的有什么问题。。我弄半天了
$str='width="325325"';
preg_replace("(\d+)", "216", $str);
或者$str='width="325325"';
str_replace("325325", "216", $str); :)
我要用preg_replace替换已知字符串中所有的width="????" 为width="216"
$str=preg_replace('(width=\"*\")','width="260"',$str)
不行啊,运行了,没有匹配到
$str='wqdqw qdqwdqd width="325325" qwdqwdqwdqw';
$str=preg_replace('(width=\"\d+\")','width="260"',$str);
echo $str;
要不你把你整个$str贴出来我看看
$str='<align="middle" height="360" width="480">';
$str=preg_replace('(width=\"\d+\")','width="260"',$str);
$str=' <align="middle" height="360" width="480">';
$str=preg_replace('(width=\"\d+\")','width="260"',$str);
echo htmlspecialchars($str);
<?
$str=preg_replace('(width=\"\d+\")','width="260"',$bqr[newstext]);
$str=preg_replace('(height=\"\d+\")','height="216"',$str);
?>
<?=$str?>
一直没有成功
<param name="AUTOSTART" value="false" />
<param name="ShowStatusBar" value="-1" />
<param name="Filename" value="/d/file/shipindianbo/2009-10-15/64a2790d9392db0fe4fc24206af3205b.wmv" /><embed width="480" height="360" type="application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" src="/d/file/shipindianbo/2009-10-15/64a2790d9392db0fe4fc24206af3205b.wmv" flename="mp"></embed></object>
$str='<object class="OBJECT" id="MediaPlayer" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" width="480" height="360" align="middle">
<param name="AUTOSTART" value="false" />
<param name="ShowStatusBar" value="-1" />
<param name="Filename" value="/d/file/shipindianbo/2009-10-15/64a2790d9392db0fe4fc24206af3205b.wmv" /> <embed width="480" height="360" type="application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" src="/d/file/shipindianbo/2009-10-15/64a2790d9392db0fe4fc24206af3205b.wmv" flename="mp"> </embed> </object>';$str=preg_replace('(width=\"\d+\")','width="200"',$str);
echo htmlspecialchars($str);
都是可以的...
<?
$str='<object class="OBJECT" id="MediaPlayer" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" width="480" height="360" align="middle">
<param name="AUTOSTART" value="false" />
<param name="ShowStatusBar" value="-1" />
<param name="Filename" value="/d/file/shipindianbo/2009-10-15/64a2790d9392db0fe4fc24206af3205b.wmv" /> <embed width="480" height="360" type="application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" src="/d/file/shipindianbo/2009-10-15/64a2790d9392db0fe4fc24206af3205b.wmv" flename="mp"> </embed> </object>';
$str=preg_replace('(width=\"\d+\")','width="260"',$str);
$str=preg_replace('(height=\"\d+\")','height="216"',$str);
?>
<?=$str?>