Code: Select all
<?php
$text = "
This is the first paragraph. The goal of this script is to wrap all paragraphs in HTML paragraph tags instead of faking them using linebreaks. Semantic markup dictates that paragraph tags be used to represent paragraphs. The other benefit is that when text is wrapped in paragraph tags, it makes it possible to style them, if desired. Margins and padding can be applied to give your paragraphs the exact look you desire them to have.
The nice feature about this script is that it preserves single newlines and converts them to html linebreak tags (br).
Sometimes you want a newline within a paragraph like this.
Sometimes you don't.
This preserves newlines while wrapping text ending with double newlines in paragraph tags.
Here is another newline within the same paragraph. Multiple newlines follow this to form a new paragraph.
Of course, I found this script and just modified it for my use. I am no expert in PHP or phpBB3, so I am not sure if I will run into other problems. That is why I am asking the nice people at the phpbb.com/community if something like this could be used in phpBB3 to give the paragraphs the semantic markup they deserve.
So, if there is anybody out there reading this who is knowledgeable about phpBB3, perhaps you could take a few seconds to look at this script and tell me if there are any reasons why this would not work in phpBB3. phpBB3 is a complex piece of software with thousands of lines of code. It would take many hours for someone like me to find out where this code should be placed in phpBB3 and spot any potential conflicts.
Thank you for your help.
Sincerely,
motumbo
";
// first, lets trim starting/trailing whitespace
$text = trim($text);
// temporarily replace two or more consecutive newlines
// into SOH characters (not used in normal text)
$text = preg_replace('~(\r\n|\n){2,}|$~', "\001", $text);
// convert remaining (i.e. single) newlines into html br's
$text = nl2br($text);
// finally, replace SOH chars with paragraphs
$text = preg_replace('/(.*?)\001/s', '<p class="post_paragraph">$1</p>' . "\n", $text);
// test
//header("Content-type: text/plain");
echo '
<html>
<body>
' .
$text .
'</body>
</html>';
?>
Code: Select all
function bbcode_nl2br($text)
{
// custom BBCodes might contain carriage returns so they
// are not converted into <br /> so now revert that
$text = str_replace(array("\n", "\r"), array('<br />', "\n"), $text);
return $text;
}
Code: Select all
function bbcode_nl2br($text)
{
// custom BBCodes might contain carriage returns so they
// are not converted into <br /> so now revert that
$text = '<p>' . str_replace(array("\n", "\r"), array('</p><p>', "\n"), $text) . '</p>';
return $text;
}
Well, you know phpBB better than I do, I'm sure. The function comments say the following:Brf wrote:No. That function is not for bbcode. It is for replacing line-breaks with <br>'s.
That lead me to believe that it the function would only be called if there were custom BB codes that needed parsing.// custom BBCodes might contain carriage returns so they
// are not converted into <br /> so now revert that
Code: Select all
function bbcode_nl2br($text)
{
// It looks like this works. Can't put in multiple lines of whitespace, though.
// first, lets trim starting/trailing whitespace
$text = trim($text);
// temporarily replace two or more consecutive newlines
// into SOH characters (not used in normal text)
$text = preg_replace('~(\r\n|\n){2,}|$~', "\001", $text);
// convert remaining (i.e. single) newlines into html br's
$text = nl2br($text);
// finally, replace SOH chars with paragraphs
$text = preg_replace('/(.*?)\001/s', '<p>$1</p>' . "\n", $text);
return $text;
}
It may be one of these in content.cssmotumbo wrote: Another issue has arisen: the style of the text is different. The font size is basically larger. I'll have to try to track down a solution to that.
Code: Select all
.panel p {
font-size: 1.2em;
margin-bottom: 1em;
line-height: 1.4em;
}
.content p {
font-family: "Lucida Grande", "Trebuchet MS", Verdana, Helvetica, Arial, sans-serif;
font-size: 1.2em;
margin-bottom: 1em;
line-height: 1.4em;
}