Please help - I'm an experienced ASP coder but I'm a raw beginner at PHP. I'm trying to create a function to format text as actual HTML paragraphs, rather than cheating and just inserting "<br />" tags. The function goes like this:
function CleanString($varstring) {
$varstring = stripslashes($varstring);
$varstring = '<p>' . $varstring . '</p>';
$varstring = str_replace("\n", "</p><p>", $varstring);
$varstring = str_replace("<p></p>", "", $varstring);
return $varstring;
}
This works great, with one exception: If there are multiple line breaks, there are multiple sets of empty paragraph tags. That's what I'm trying to correct in the last line of the function, but I'm having no luck. Any help would be greatly appreciated.