Php 首先匹配并替换<;p>;输出的段落内容?
我有通过Wordpress输出的内容,它将段落Php 首先匹配并替换<;p>;输出的段落内容?,php,regex,preg-replace,Php,Regex,Preg Replace,我有通过Wordpress输出的内容,它将段落标记环绕在内容周围。我需要删除第一个中的内容。。我该怎么做 例如,输出为: <p>Posted by Bob</p> <p>This is the content here</p> <p>This is the second paragraph</p> 由Bob发布 这是这里的内容 这是第二段 我想删除Bob发布的第行,并保留其余部分 如果您有权访问jQuery,则可以使用以
标记环绕在内容周围。我需要删除第一个
中的内容。。我该怎么做
例如,输出为:
<p>Posted by Bob</p>
<p>This is the content here</p>
<p>This is the second paragraph</p>
由Bob发布
这是这里的内容
这是第二段
我想删除Bob发布的第
行,并保留其余部分 如果您有权访问jQuery,则可以使用以下命令:
$("p:first-child").text("Hello World!");
要在WordPress中包含jQuery,请在
中添加以下内容:
这以安全的方式包括jQuery,并防止与jQuery的其他实例或其他库发生任何冲突。一般来说
在这种情况下,正则表达式解决方案可能工作正常,但:
$str = preg_replace('~<p>.*?</p>~s', '', $str, 1);
同样,如果您只想清空标记,但保留它,请将outertext
替换为innertext
是否尝试替换内容或删除整个标记?
$str = preg_replace('~<p>.*?</p>~s', '', $str, 1);
require "simple_html_dom.php";
$html = new simple_html_dom($input);
$html->load($input);
$html->find('p', 0)->outertext = "";
$output = $html->save();