SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,931
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Wrap Form Text in <p> Tags??

    In my Q&A Form, I have a series of 10 TextAreas where Users can type long-winded responses to the Questions on the Form.

    Let's say that someone types in...
    Wildlife Conservation Society researchers have captured video footage of the world’s rarest gorilla using camera traps, providing a stunning look at animals that usually flee at the first sight of humans.

    Eight Cross River gorillas traveling across a forest path were filmed by one of four video camera traps researchers set in Cameroon’s Kagwene Gorilla Sanctuary. A combination of habitat destruction and hunting has reduced the species’ total population to less than 250, making it the world’s rarest gorilla.

    Christopher Jameson, who directs WCS’s Takamanda Mone Landscape Project, said the video “represents the best images to date of Cross River gorillas.”

    When I go to store that in my database, and later display it, I would like it to look like this...
    <p>Wildlife Conservation Society researchers have captured video footage of the world’s rarest gorilla using camera traps, providing a stunning look at animals that usually flee at the first sight of humans.</p>

    <p>Eight Cross River gorillas traveling across a forest path were filmed by one of four video camera traps researchers set in Cameroon’s Kagwene Gorilla Sanctuary. A combination of habitat destruction and hunting has reduced the species’ total population to less than 250, making it the world’s rarest gorilla.</p>

    <p>Christopher Jameson, who directs WCS’s Takamanda Mone Landscape Project, said the video “represents the best images to date of Cross River gorillas.”</p>
    Why?

    First of all, because that is how it should be marked up in HTML.

    Secondly, if I don't have <p> around each paragraph, then I lose all ability to style things...

    I hope this isn't hard to do?!

    Help needed!

    Thanks,


    Debbie

  2. #2
    SitePoint Member
    Join Date
    Oct 2009
    Location
    Sydney
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi DoubleDee
    You can incorporate TinyMCE into your website and this will format the text as you want (Google it to find out more) very easy to implement! OR If it's a formatting thing that you want as you display the content on another page, just wrap the output of your php/mysql query in the [<p>] tags and apply the css as you like.
    Hope this helps, Cheers from Sydney Australia!

  3. #3
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,931
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Drignoid View Post
    Hi DoubleDee
    You can incorporate TinyMCE into your website and this will format the text as you want (Google it to find out more) very easy to implement!
    Thanks, but I want to hold off on things like TinyMCE for now.


    OR If it's a formatting thing that you want as you display the content on another page, just wrap the output of your php/mysql query in the [<p>] tags and apply the css as you like.

    Hope this helps, Cheers from Sydney Australia!
    The only problem with that is if I want to change the styles for each paragraph, then wrapping all paragraphs in one <p></p> pair does nothing for me.

    Ya know?


    Debbie

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    You should store the content as-is, and not bias it to one format or another. You should defer this process to when you display the content, doing so allows you to render the content differently depending on the situation.

    You'll find yourself stripping these back out more often that not, it's easier to add them when/where/if required.

    Check out how Wordpress handles this.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,931
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AnthonySterling View Post
    You should store the content as-is, and not bias it to one format or another. You should defer this process to when you display the content, doing so allows you to render the content differently depending on the situation.

    You'll find yourself stripping these back out more often that not, it's easier to add them when/where/if required.

    Check out how Wordpress handles this.
    No wonder people hate WordPress...

    Here is my attempt at things...
    PHP Code:
    $text="I decided to start my own business because I want to be my own boss!



    My boss is a jerk and never appreciates anything that I do for him, so why put up with the abuse?!  He takes me for granted and doesn't appreciate all of my talents.

    Running my own business will give me a chance to do things as I see fit...

    Line One
    Line Two
    Line Three
    Line Four



    Line Eight

    Line Ten"
    ;


    $text2 htmlentities($textENT_QUOTES);


    function 
    nl2p($string$line_breaks true) {
        
    // Remove existing HTML formatting to avoid double tags.
    //^    $string = str_replace(array('<p>', '</p>', '<br>', '<br/>'), '', $string);

        // Replace Carriage Return with Empty String.
        // Replace multiple Newlines with closing & opening paragraph tags.
        // Replace single Newline with break tag.
        
    if ($line_breaks == true) {
            return 
    '<p>'.preg_replace(array("#\r#""#\n{3,}#""#\n{2}#""#\n#"), array("""</p><br /><p>""</p><p>""<br />\n"), $string).'</p>';
    //        return '<p>'.preg_replace(array("#\r#","#\n{2,}#", "#\n#"), array("","</p><p>", "<br />\n"), $string).'</p>';
        
    }else{
            return 
    '<p>'.preg_replace("#\n#""</p><p>"trim($string)).'</p>';
        }
    }

    echo 
    nl2p($text2TRUE); 
    It works exactly as I want - except for the fact that if there are multiple carriage returns between lines then I don't know how to count how many there are and add the corresponding number of breaks <br /> into my code, so instead I just add one break as a consolation!

    If anyone can help me fix that last part, then that would be great!!


    Debbie


Bookmarks

Posting Permissions

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