替换字符串中的 width="325325" 为 width="216"的正则表达式

解决方案 »

  1.   


    $str='width="325325"';
    preg_replace("(\d+)", "216", $str);
    或者$str='width="325325"';
    str_replace("325325", "216", $str);  :)
      

  2.   

    不是这个意思
    我要用preg_replace替换已知字符串中所有的width="????" 为width="216"
      

  3.   

    写成这样,但是不对!不知道原因
    $str=preg_replace('(width=\"*\")','width="260"',$str)
      

  4.   

    $str=preg_replace('(width=\"\d+\")','width="260"',$str);
      

  5.   

    $str=preg_replace('(width=\"\d+\")','width="260"',$str);
    不行啊,运行了,没有匹配到
      

  6.   

    我试过,完全可以
    $str='wqdqw qdqwdqd width="325325"  qwdqwdqwdqw';
    $str=preg_replace('(width=\"\d+\")','width="260"',$str);
    echo $str;
    要不你把你整个$str贴出来我看看
      

  7.   

    测试例子,没有成功.
    $str='<align="middle" height="360" width="480">';
    $str=preg_replace('(width=\"\d+\")','width="260"',$str); 
      

  8.   

    可是...明明成功了呀...
    $str=' <align="middle" height="360" width="480">';
    $str=preg_replace('(width=\"\d+\")','width="260"',$str);
    echo htmlspecialchars($str); 
      

  9.   

    或者不用htmlspecialchars, 直接查看源代码也行,确实是成功了.
      

  10.   

    那就奇怪了,我是在帝国cms里面写的bqr[newstext]中含有width="480"
    <?
    $str=preg_replace('(width=\"\d+\")','width="260"',$bqr[newstext]);
    $str=preg_replace('(height=\"\d+\")','height="216"',$str);
    ?>
    <?=$str?>
    一直没有成功
      

  11.   

    <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>
      

  12.   

    这我就不清楚了``那个$bqr[newstext]是不是需要转换一下字符格式之类的?
      

  13.   

    直接
    $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); 
    都是可以的...
      

  14.   

    郁闷,单独写个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?>
      

  15.   

    呃..爱莫能助了...把那个$bqr[newstext]转换下行吗?用htmlspecialchars之类的`然后正则`然后再转回来???我也不懂了...祝你好运吧