preg_replace的使用问题?

好磁力 2014-02-23 02:16:44

如图所示。在原来的基础上增加一个img标签 地址参数调用前面超文本的参数。
另外一段代码有很多个这样的结构标签 我都要替换。 不能用array了吧?
...全文
132 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
嘻哈大咖秀 2014-02-23
  • 打赏
  • 举报
回复
$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]."' width='155' heigth='120'>";
	$html = str_replace($value, $newValue, $html);
}
var_dump($html);

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧