首頁  >  文章  >  後端開發  >  preg_replace的使用问题?

preg_replace的使用问题?

WBOY
WBOY原創
2016-06-23 14:01:54848瀏覽

本帖最后由 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