1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to Displaythe text in multiple lines when retrieving from table?

Discussion in 'PHP' started by iitstudent, Jul 21, 2013.

  1. #1
    Hi I have a table in which my row contains the text which i retrieve from the database.But i have a small width of row and the data i retrieve is large.And the text exceeds the width of my row so i want to break the data i retrieve into multi lines inside the table row.How can i do it.
     
    iitstudent, Jul 21, 2013 IP
  2. perfectdragon

    perfectdragon Banned

    Messages:
    42
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    13
    #2
    You could use the function wordwrap(). It wraps a string to a given number of characters using a string break character. or even you can use nl2br function if you are getting text from the table which is input in the table using multiline text box
     
    perfectdragon, Jul 21, 2013 IP
    designpack, technoguy and iitstudent like this.
  3. (BN)Nolan

    (BN)Nolan Well-Known Member

    Messages:
    74
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    135
    #3
    I'd agree with him 100%. I'm still learning a lot with PHP but from what I know, this would probably be your best option. +1
     
    (BN)Nolan, Jul 21, 2013 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #4
    I would suggest what was originally an IE only property from 15 years ago, that is now part of the CSS3 specification so all the "modern" browsers now support it.

    word-wrap:break-word;

    https://developer.mozilla.org/en-US/docs/Web/CSS/word-wrap

    "CSS3" property that works all the way back to IE 5.5 -- Fun stuff. (and about blasted time!!!)
     
    deathshadow, Jul 22, 2013 IP
  5. Ronnie403

    Ronnie403 Active Member

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    80
    Digital Goods:
    8
    #5
    for the best compatibility use wordwrap(); like so
    wordwrap($text, 20, "<br />\n");
    Code (markup):
     
    Ronnie403, Jul 26, 2013 IP
  6. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #6
    Assuming you can live with some crappy fixed width asshattery.
     
    deathshadow, Jul 26, 2013 IP
  7. Ronnie403

    Ronnie403 Active Member

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    80
    Digital Goods:
    8
    #7
    Thats just an example.
    Its good when you have to work with stuff like this like comments, posts, quotes, etc...
     
    Ronnie403, Jul 26, 2013 IP
  8. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #8
    In other words content, stuff that shouldn't ever have forced formatting on it in the markup since it should be in a dynamic layout.

    Just saying. Processing it server-side fixed was a stopgap for everything other than IE being a retard. Now that CSS3 has taken a decade and a half old IE5 value and made it official, and it's supported in any browser that actually matters (and a hell of a lot that don't) there's no reason to waste time on doing it via brute force.

    CSS3 -- the bleeding edge of what IE could do a decade and a half ago!
     
    deathshadow, Jul 26, 2013 IP
    ryan_uk likes this.
  9. Ronnie403

    Ronnie403 Active Member

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    80
    Digital Goods:
    8
    #9
    But he has a point overall, ie sucks even with js you have to do alot of stuff to get ie to work which can easily be done with other browsers.
    Now lets try to stay on topic =]
     
    Ronnie403, Jul 26, 2013 IP