php – preg_replace”with”?
发布时间:2020-12-13 16:26:36 所属栏目:PHP教程 来源:网络整理
导读:我的代码删除了 p开始标签,但现在我想替换结尾的 / p带有换行符的标签我该怎么做? 这是我有的: $content = 'This is the content';$newcontent = preg_replace("/p[^]*?","",$content);$newcontent = preg_replace("/p","br /",$newcontent); 使用str_repl
我的代码删除了< p>开始标签,但现在我想替换结尾的< / p>带有换行符的标签我该怎么做?
这是我有的: $content = 'This is the content'; $newcontent = preg_replace("/<p[^>]*?>","",$content); $newcontent = preg_replace("</p>","<br />",$newcontent);
使用str_replace而不是preg_replace,所以:
$content = '<p>This is a new content for missing slash</p>'; $newcontent = preg_replace("/<p[^>]*?>/",$content); $newcontent = str_replace("</p>",$newcontent); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |