My database stores articles in a plaintext format so when I retrieve it from the database there are no html tags around the actual paragraphs of the article.
I am trying to have a php function that takes the article and wraps only the paragraphs in a <p> tag.
The problem I am having is that I cannot make my regular expression work to only recognize the true paragraphs compared to code examples...
An example of before and after is below
Before:
[text]Aliquam erat volutpat. Morbi at justo lacus. Sed id dui felis, in fringilla urna. Aliquam erat volutpat. Maecenas nec diam ullamcorper nisi scelerisque vehicula. Sed sed consectetur augue.
<code><? echo "this is on a single line"; ?></code>
<code>
<?php
echo "this is a multiline code block";
?>
</code>
Maecenas eleifend egestas nisi ac fringilla. Integer lacinia posuere diam vitae aliquet. Donec augue diam, feugiat nec rhoncus id, lacinia sit amet libero. Nam eu commodo mauris.
[/text]
After
[text]<p>Aliquam erat volutpat. Morbi at justo lacus. Sed id dui felis, in fringilla urna. Aliquam erat volutpat. Maecenas nec diam ullamcorper nisi scelerisque vehicula. Sed sed consectetur augue. </p>
<code><? echo "this is on a single line"; ?></code>
<code>
<?php
echo "this is a multiline code block";
?>
</code>
<p>Maecenas eleifend egestas nisi ac fringilla. Integer lacinia posuere diam vitae aliquet. Donec augue diam, feugiat nec rhoncus id, lacinia sit amet libero. Nam eu commodo mauris. </p>
[/text]
Wrapping only paragraphs in a <p> tag
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Wrapping only paragraphs in a <p> tag
How do you get the code tags around the sections that contains code samples?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering