首页  >  文章  >  后端开发  >  preg_replace的使用问题?

preg_replace的使用问题?

WBOY
WBOY原创
2016-06-23 14:01:54845浏览

本帖最后由 u013747505 于 2014-02-23 16:36:03 编辑

preg_replace


如图所示。在原来的基础上增加一个img标签 地址参数调用前面超文本的参数。
另外一段代码有很多个这样的结构标签 我都要替换。 不能用array了吧?

回复讨论(解决方案)

$html = <<<html<div class="abc"><a href="hash.php?a=123" target="_blank">ca<font>s</font>d</a></div><div class="abc"><a href="hash.php?a=456" target="_blank">casd</a></div>html;preg_match_all('/<div\s*class=\"abc\">\s*<a href=\"hash\.php\?a=(.*?)\" target=\"_blank\">(?:.*?)<\/a>/i', $html, $match);foreach ($match[0] as $key => $value) {	$newValue = $value."\n<img  src='tr.php?hash=".$match[1][$key]."'    style="max-width:90%" heigth='120' alt="preg_replace的使用问题?" >";	$html = str_replace($value, $newValue, $html);}var_dump($html);

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn