Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Aug 2004
    Location
    The US of A
    Posts
    767
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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;
            } 

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Aug 2004
    Location
    The US of A
    Posts
    767
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?

  • #4
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    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.

  • #5
    Regular Coder
    Join Date
    Aug 2004
    Location
    The US of A
    Posts
    767
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I was explaining it poorly, but I found a solution here . =D


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •