Kurashu
03-26-2005, 07:41 AM
Currently, I have a basic nl2p function it wraps the text in a <p> tag and then, for every \n it replaces with a </p><p> with an optional CSS class on the opening. However, if you examine this:
However, then I end up with something like this....
<p>Grab open the door</p>
<p>I can actually see my breath tonight</p>
<p>That doesnt mean im breathing</p>
<p>Crack the smile just for the stake of me</p>
<p>This could take a while when im loud</p>
<p>Silence is golden especially in this case</p>
<p>I'm not too sure that I want it to be this way</p>
<p>Open mouth closed eyes</p>
<p>No ones are escaping</p>
<p>It's our nerve</p>
<p>It's to die to see were inventing</p>
<p>The way it all fits together at night</p>
<p>Together at night</p>
<p>I think it's time to turn around</p>
<p>I really wanted you all tonight</p>
<p>I think it's... <a href="#" class="more">Read More</a></p>
Not exactly what I'd want. Not to mention that there will eventually be code included into this project (by that I mean, along the lines of ALA). And speaking of ALA, that's more what I am aiming for, but would it be easier for me to code in the HTML by hand (e.g. add every paragraph, etc, etc)?
Current PHP Code:
function nl2p($text, $class='')
{
$class = ( ($class != '') ? ' class="' . $class . '"' : '');
$text = '<p' . $class . '>' . $text . '</p>';
$text = str_replace("\n",'</p><p' . $class . '>',$text);
$text = str_replace("\r",'',$text);
$text = str_replace('<p' . $class . '></p>','',$text);
$text = str_replace('</p><p' . $class . '>', "</p>\n<p". $class . ">", $text);
return $text;
}
However, then I end up with something like this....
<p>Grab open the door</p>
<p>I can actually see my breath tonight</p>
<p>That doesnt mean im breathing</p>
<p>Crack the smile just for the stake of me</p>
<p>This could take a while when im loud</p>
<p>Silence is golden especially in this case</p>
<p>I'm not too sure that I want it to be this way</p>
<p>Open mouth closed eyes</p>
<p>No ones are escaping</p>
<p>It's our nerve</p>
<p>It's to die to see were inventing</p>
<p>The way it all fits together at night</p>
<p>Together at night</p>
<p>I think it's time to turn around</p>
<p>I really wanted you all tonight</p>
<p>I think it's... <a href="#" class="more">Read More</a></p>
Not exactly what I'd want. Not to mention that there will eventually be code included into this project (by that I mean, along the lines of ALA). And speaking of ALA, that's more what I am aiming for, but would it be easier for me to code in the HTML by hand (e.g. add every paragraph, etc, etc)?
Current PHP Code:
function nl2p($text, $class='')
{
$class = ( ($class != '') ? ' class="' . $class . '"' : '');
$text = '<p' . $class . '>' . $text . '</p>';
$text = str_replace("\n",'</p><p' . $class . '>',$text);
$text = str_replace("\r",'',$text);
$text = str_replace('<p' . $class . '></p>','',$text);
$text = str_replace('</p><p' . $class . '>', "</p>\n<p". $class . ">", $text);
return $text;
}