Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-26-2005, 07:41 AM   PM User | #1
Kurashu
Regular Coder

 
Join Date: Aug 2004
Location: The US of A
Posts: 767
Thanks: 1
Thanked 0 Times in 0 Posts
Kurashu is an unknown quantity at this point
Making a smarter paragraph former?

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....

Code:
<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:
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;
        } 
Kurashu is offline   Reply With Quote
Old 03-26-2005, 03:36 PM   PM User | #2
marek_mar
Sensei


 
Join Date: Aug 2003
Location: One step ahead of you.
Posts: 2,815
Thanks: 0
Thanked 3 Times in 3 Posts
marek_mar is on a distinguished road
Quote:
Originally Posted by Kurashu
Not exactly what I'd want.
What do you want?
__________________
I'm not sure if this was any help, but I hope it didn't make you stupider.

Experience is something you get just after you really need it.
PHP Installation Guide Feedback welcome.
marek_mar is offline   Reply With Quote
Old 03-26-2005, 04:50 PM   PM User | #3
Kurashu
Regular Coder

 
Join Date: Aug 2004
Location: The US of A
Posts: 767
Thanks: 1
Thanked 0 Times in 0 Posts
Kurashu is an unknown quantity at this point
I don't want a paragraph formed on every new line, especially if I am going to be adding something along the lines of BB code. Maybe ALA was a bad example...something like a forum is a better example. Take here for instance.


I can type this.
  • And
  • Then
  • Have
  • This
  • List

And then maybe an image and a link, the whole nine yards, but there aren't breaks placed at the end of whatever list the[list]
tag is made into (<ol> I think >_>) and there aren't breaks after of the </li>s (At least I hope not, then my point is moot even though they shouldn't be there in the first place).

Is that a better example?
Kurashu is offline   Reply With Quote
Old 03-26-2005, 05:55 PM   PM User | #4
marek_mar
Sensei


 
Join Date: Aug 2003
Location: One step ahead of you.
Posts: 2,815
Thanks: 0
Thanked 3 Times in 3 Posts
marek_mar is on a distinguished road
Ok so you want to do something like bbcode? I still don't know what you want to do with the <p> tag. How the tags are displayed is rather browser depending not php.
__________________
I'm not sure if this was any help, but I hope it didn't make you stupider.

Experience is something you get just after you really need it.
PHP Installation Guide Feedback welcome.
marek_mar is offline   Reply With Quote
Old 03-26-2005, 07:49 PM   PM User | #5
Kurashu
Regular Coder

 
Join Date: Aug 2004
Location: The US of A
Posts: 767
Thanks: 1
Thanked 0 Times in 0 Posts
Kurashu is an unknown quantity at this point
I was explaining it poorly, but I found a solution here . =D
Kurashu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:43 AM.


Advertisement
Log in to turn off these ads.