Forum Moderators: coopster
I've developed a blog system on my site, and it's working really, really well, bit I noticed today that there is a small bug when browsing the site using Firefox.
Once into the site, the front page displays the last few blogs, with a read more link.
The problem is, I use the following codes to spint out the blogs:
<?php require("config/connections.php");?>
<?php do {?>
<?php require("config/funky.php");?>
<h2><u><?php echo nl2br($output['title']);?></u></h2>
<?php echo nl2br(substr($output['news'],0,300));?>.....<br /></p>
<p><? echo "<a href=\"post.php?id=" . nl2br($output["id"]). "\"> --> Read More?</a>" ;?></p>
<h2><?php echo nl2br($output['date']) ;?></h2>
<hr />
<?php } while ($output = mysql_fetch_array($getnews));?> The nl2br(substr($output['news'],0,300)) string displays the first 300 charecters from the blog entry, but if during these 300, there is a normal HTML tag that starts but is cut off, the formatting is transferred all the wat though the site. It only happens when browsing wih Firefox. IE seems to understand that I want it to stop.
Is there a way that I could modify my code to finish off the tag so that it's not replicated going down the page?
I would assume that I can't just chuck in all the possible ending tags, becuase this wouldn't make it XHTML compliant.
function close_tags($string) {
$iteration = 0;
while (preg_match('/.*(<([^>\/]+)>)(?!.*<\/\2>)/', $string, $matches) ) {
$tag = $matches[2];
$string = $string . "</$tag>";
if (++$iteration > 100) die("Regex problem") ;
}
return $string;
}
Regarding nl2br, I picked this little function up in these forums a couple of years ago, which works great:
function nl2p($content) {
$content = explode("\n",$content);
foreach($content as $key => $line) {
$lines[$key] = "<p>".$line."</p>";
}
$content = implode("\n",$lines);
return $content;
}
WBF
I modified the code on the following line from:
<?php echo nl2br(substr($output['news'],0,300));?>
To
<?php echo nl2br(strip_tags(substr($output['news'],0,300)));?>
And this works perfectly.
willybfriendly, the function that you describe, what would the purpose of that be? I assume it would have the same effect as using nl2br?