Using php to retrieve from mysql a long text

Discussion in 'PHP' started by OPETH, Jan 26, 2009.

  1. #1
    Hi all!

    I stored a long text in content field on mysql database.I used html tag for paragraph in the content field. But i dont want to use html tag in mysql database.

    how i can retrieve from mysql the long text in the content field , like seperate paragraph.
     
    OPETH, Jan 26, 2009 IP
  2. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #2
    You have to use a regular expression I guess
     
    nabil_kadimi, Jan 26, 2009 IP
  3. CTThompson

    CTThompson Member

    Messages:
    68
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #3
    If I understand your question correctly...

    You'll have to pull the entire long text string at once. I am not aware of a way you can grab "part" of it.

    Once you have the string in PHP, do an explode based on the paragraph tag. It'll split your string into an array of paragraphs.

    Something like:

    $my_text = get data from MySQL;
    $exploded = explode("<p>", $my_text);

    Then $exploded[0], $exploded[1], etc will exist with segments of your text string.

    A third step may be required, which is stripping out the trailing </p> tags.
     
    CTThompson, Jan 26, 2009 IP
  4. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #4
    use html_entity_decode(); this will disregard all html tags and output a string
     
    bartolay13, Jan 26, 2009 IP
  5. OPETH

    OPETH Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Actually i have to design correctly my database.

    For example,how to make it if you want to design a database for aticles.

    article_name field and all paragraphs of the article in atricle_name or a paragraph1,paragraph2... field names for each paragraph.

    Which one?
     
    OPETH, Jan 27, 2009 IP
  6. hassanahmad1

    hassanahmad1 Active Member

    Messages:
    150
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #6
    if you dont want to use html tags then use \n where you want to insert a new line
    and before showing the records, use the function nl2br()
     
    hassanahmad1, Jan 27, 2009 IP
  7. OPETH

    OPETH Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Should i save in mysql with <p> ?



    Should i save in mysql withoout <p> ?

     
    OPETH, Jan 27, 2009 IP
  8. hassanahmad1

    hassanahmad1 Active Member

    Messages:
    150
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #8
    just without <p>
    but with normal line breaks
     
    hassanahmad1, Jan 27, 2009 IP
  9. Gangsta

    Gangsta Active Member

    Messages:
    145
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #9
    explain why you do not want html in database?
     
    Gangsta, Jan 27, 2009 IP