Home > Backend Development > PHP Tutorial > preg_replace的使用问题?

preg_replace的使用问题?

WBOY
Release: 2016-06-23 14:01:54
Original
935 people have browsed it

本帖最后由 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);
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template