I will try to explain in more detail. The project is a blogging platform using a flatfile database. Entries are typed into a form, and the blogger is able to use select BBCode tags for formatting. The entry is saved to a text file and then redisplayed on other pages with the BBCode tags converted to html.
So, for instance, a text file for an entry might read:
[title]Entry Title[/title]
2009-04-25
[subtitle]Entry Subtitle[/subtitle]
This is a paragraph with [i]some italics[/i] and a [url=
http://www.whatever.com]link[/url] to [url]
http://www.whatever.com[/url].
[quote]This is a block quotation.[/quote]
But then the php script that pulls up the text file and creates the visible blog entry includes these lines:
$entry=file_get_contents('text file displayed above');
$entry=htmlentities($entry, ENT_QUOTES, 'UTF-8');
$entry=str_replace("\r", '', $entry);
$entry="<p>$entry</p>";
$entry=str_replace("\n", "</p>\n<p>", $entry);
$entry=str_replace('<p></p>', '<p> </p>', $entry);
$entry=preg_replace('|<p>\[title](.+)\[/title]</p>|', '<p class="title">$1</p>', $entry);
$entry=preg_replace('|<p>\[subtitle](.+)\[/subtitle]</p>|', '<p class="subtitle">$1</p>', $entry);
$entry=preg_replace('|<p>\[quote](.+)\[/quote]</p>|', '<p class="quote">$1</p>', $entry);
$entry=preg_replace('|\[i](.+)\[/i]|', '<span class="italics">$1</span>', $entry);
$entry=preg_replace('|\[url](.+)\[/url]|', '<a href="$1">$1</a>', $entry);
$entry=preg_replace('|\[url=(.+)](.+)\[/url]|', '<a href="$1">$2</a>', $entry);
So the resulting html looks like this:
<p class="title">Entry Title</p>
<p>2009-04-25</p>
<p> </p>
<p class="subtitle">Entry Subtitle</p>
<p> </p>
<p>This is a paragraph with <span class="italics">some italics</span> and a <a href="http://www.whatever.com">link</a> to <a href="http://www.whatever.com">http://www.whatever.com</a>.</p>
<p> </p>
<p class="quote">This is a block quotation.</p>
This is all good for block quotations that contain prose, but it does not allow for poetry and such, where there will be newline characters within the quote.
[quote]Lord, make me an instrument of Thy peace;
where there is hatred, let me sow love;
where there is injury, pardon;
where there is doubt, faith;
where there is despair, hope;
where there is darkness, light;
and where there is sadness, joy.[/quote]
Becomes
<p class="quote">Lord, make me an instrument of Thy peace;</p>
<p>where there is hatred, let me sow love;</p>
<p>where there is injury, pardon;</p>
<p>where there is doubt, faith;</p>
<p>where there is despair, hope;</p>
<p>where there is darkness, light;</p>
<p>and where there is sadness, joy.</p>
So, instead of this...
$entry=preg_replace('|<p>\[quote](.+)\[/quote]</p>|', '<p class="quote">$1</p>', $entry);
... I need something that will locate <p>[quote] and [/quote]</p> and then change all <p> tags between into <p class="quote">.
Hope that clarifies. Any ideas?
Thanks,
Drew