我有我的代码删除<p>起始标记,但现在我想</p>用换行符替换结束标记.我怎样才能做到这一点?
这就是我所拥有的:
$content = 'This is the content';
$newcontent = preg_replace("/<p[^>]*?>", "", $content);
$newcontent = preg_replace("</p>", "<br />", $newcontent);
Run Code Online (Sandbox Code Playgroud)
Ric*_*uez 29
使用str_replace而不是preg_replace,所以:
$content = '<p>This is a new content for missing slash</p>';
$newcontent = preg_replace("/<p[^>]*?>/", "", $content);
$newcontent = str_replace("</p>", "<br />", $newcontent);
Run Code Online (Sandbox Code Playgroud)
小智 6
$content = preg_replace('#<p(.*?)>(.*?)</p>#is', '$2<br/>', $content);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21591 次 |
| 最近记录: |