Created
September 15, 2011 23:07
-
-
Save martinjlowm/1220745 to your computer and use it in GitHub Desktop.
Replace HTML paragraphs with breaks, assuming the content is in a <p>-wrapper that we want to keep.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$bodyText = $content['field_body']; // This is incorrect, the structure is different (use var_dump to figure it out) | |
$ptOne = substr($bodyText, 0, 3); // <p> - 0, 1, 2 | |
$ptTwo = substr($bodyText, 3, -4); // text inside wrapper | |
$ptThree = substr($bodyText, -4); // </p> - 0, 1, 2, 3 | |
$newcontent = preg_replace("/<p[^>]*?>/", "", $ptTwo); | |
$newcontent = str_replace("</p>", "<br /><br />", $newcontent); | |
$newcontent = $ptOne . $newcontent . $ptThree; | |
print render($newcontent); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment