- Where Developers Learn, Share, & Build Careers
I have content that is being output via Wordpress, and this article is For example, the output is: I line In this case, a regex solution can work fine though Important things are If you want only to remove the contents of the tag (if you want to keep an empty paragraph), just click However, as It is still not the right solution. Tags or comments about tags, or Even if you want to empty the tag but want to keep it, then and lt; P & gt; Wrap the tag around content around me & lt; P & gt; & Lt; / P & gt; Need to remove content in . How can I do this?
& lt; P & gt; Posted by Bob & lt; / P & gt; & Lt; P & gt; This is the content here & lt; / P & gt; & Lt; P & gt; This is the second paragraph & lt; / P & gt; & lt; P & gt; Posted by Bob & lt; / P & gt; and want to leave the rest. In general,. $ str = preg_replace ('~ & lt; p & gt; *? & Lt; / p & gt; ~ s,' ', $ str, 1);
? creates . * ungreedy (so that it stops as soon as possible and very last & lt; / p & gt; s . is capable of matching new lines 1 which removes only the first match
"Simple_html_dom.php" is required; $ html = new simple_html_dom ($ input); $ html- & gt; load ($ input); $ Html- & gt; search ('P', 0) - & gt; External text = ""; $ Output = $ html-> Save (); external text with internal text Change .
Comments
Post a Comment