Mysql question! how can i put space if there is more than 50 character?

Discussion in 'PHP' started by baris22, Dec 6, 2007.

  1. #1
    Hello,

    I am trying to display information from the database, if i get long sentence without break or space it does not fit to my table and breaks my design.

    My code is

    
    
    <table width="720" border="0" align="center" cellpadding="0" cellspacing="0">
    		  <tr>
    		    <td align="left">'.$row['description'].'</td>
    		  </tr>
    		</table>
    
    
    PHP:
    When i get something like this

    sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss

    from database it messes with my design. What can i do?


    Thanks
     
    baris22, Dec 6, 2007 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    maybe this will give you some idea..

    **LEFT(str,len)

    Returns the leftmost len characters from the string str, or NULL if any argument is NULL.

    mysql> SELECT LEFT('foobarbar', 5);
    -> 'fooba'


    ***LENGTH(str)

    Returns the length of the string str, measured in bytes. A multi-byte character counts as multiple bytes. This means that for a string containing five two-byte characters, LENGTH() returns 10, whereas CHAR_LENGTH() returns 5.

    mysql> SELECT LENGTH('text');
    -> 4

    hope this help
     
    bartolay13, Dec 6, 2007 IP
  3. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #3
    ok. i sorted.

    
    $text=$row['description'];
    $newtext = wordwrap($text, 100, "\n", true);
    echo "$newtext\n";
    
    
    PHP:
     
    baris22, Dec 6, 2007 IP
  4. arnek

    arnek Active Member

    Messages:
    134
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #4
    ooh - nice fix...

    I would never have thought of that one
     
    arnek, Dec 9, 2007 IP