Convert <P> tags to <BR>
Posted: Fri Apr 28, 2006 1:39 am
I've always really hated paragraph tags (I prefer to use BR's) and have just implemented a rich HTML editor into my site's custom CMS. The only problem is, the editor can only accept P tags by default. So, once I've submitted that and it's in my database, this is how an entry looks, once extracted:
I want to remove all of the P tags, replacing them with <br> tags, and I was going to use the following code to do it:
However, that means that the final part of each entry will be two line breaks (whereas I don't want any since I'm pulling out multiple entries at once). So, my question is: How would I make a simple way of ensuring that all paragraphs are converted to line breaks, but the very last replace shouldn't occur?
I hope that's not too confusing...
Code: Select all
<span class="article_body"><p>How well does this work?</p><p> </p><p>This should be two lines <strong>dow</strong>n.</p><p> </p><p> </p><p>This should be three lines down! </p></span>
<a href="index.php?view=news&id=5"><img src="images/read_more.gif" alt="read the full article" border="0"></a>Code: Select all
$bad = array("<p>", "</p>", " ");
$good = array("", "<br /><br />", "");
$_POST['article'] = str_replace($bad, $good, $_POST['article']);I hope that's not too confusing...