Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这个
[caption]<img />[/caption]
我已经删除了使用这个的标题标签
$content = preg_replace("/\[.*?\]/", "", $content);
但是,我想用这样的 div 替换它
<div><img></div>
我错过了什么?任何帮助表示赞赏。
你可以试试:
$search_for = '/\[caption\](.*?)\[\/caption\]/is'; $replace_with = '<div>$1</div>'; $str = "[caption]<img />[/caption]"; $replaced = preg_replace($search_for, $replace_with, $str); echo $replaced;