首页  >  文章  >  后端开发  >  替换字符串的有关问题

替换字符串的有关问题

WBOY
WBOY原创
2016-06-13 10:14:16855浏览

替换字符串的问题
不用js,想将替换字符串width="80" height="80",如何写呢?
传入字符串

HTML code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><img     style="max-width:90%" src="http://www.macaucentral.com/dev/images/stories/jreviews/649_Image00001_1304589016.jpg" alt="替换字符串的有关问题" >

传出字符串
HTML code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><img     style="max-width:90%"  style="max-width:90%" src="http://www.macaucentral.com/dev/images/stories/jreviews/649_Image00001_1304589016.jpg" alt="替换字符串的有关问题" >



------解决方案--------------------
echo str_replace('width="200"','width="80" height="80"',$str);
------解决方案--------------------
PHP code
<?php $str='<img     style="max-width:90%" src="http://www.macaucentral.com/dev/images/stories/jreviews/649_Image00001_1304589016.jpg" alt="替换字符串的有关问题" >';echo preg_replace('/width="\d+"/','width="80"  style="max-width:90%",$str);<br><font color="#e78608">------解决方案--------------------</font><br>如果要在前台展示的时候动态替换的话那就非js莫属了。<br>要是后台那就php处理吧<div class="clear">
                 
              
              
        
            </div>
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn