wrap text

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bnashenas1984
    Contributor
    • Sep 2007
    • 257

    wrap text

    Hello everyone
    as you see below i have a table which contains some text. The text written in this table comes from a database which is sent by users.
    My problem is that if some user writes a text without spaces longer than this table then the table will be stretched but i want the text to be wraped instead ( break )

    [code=php]
    <table width="100" >
    <tr>
    <td>

    <?PHP
    print $text;
    ?>

    </td>
    </tr>
    </table>
    [/code]
    Last edited by Atli; Sep 17 '07, 08:47 PM. Reason: Added [code] tags
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    Check out the wordwrap() function.

    P.S. Please post your code inside [code] tags.

    Comment

    • Deepamathi
      New Member
      • Sep 2007
      • 3

      #3
      Use the style WORD-BREAK:BREAK-ALL; the breaking happens even if there is no delimiters in the text

      Comment

      • kovik
        Recognized Expert Top Contributor
        • Jun 2007
        • 1044

        #4
        Originally posted by Deepamathi
        Use the style WORD-BREAK:BREAK-ALL; the breaking happens even if there is no delimiters in the text
        I'd recommend the wordwrap() route. word-break is relatively new to the CSS spec (I believe it is a CSS3 property) and not all browsers support it (all *major* browsers do though, but wordwrap() gives you more control and less risk). Also, you can add a character such as "-" to indicate line wrapping.

        Comment

        • bnashenas1984
          Contributor
          • Sep 2007
          • 257

          #5
          thanks for your replies...
          But the problem with wordwrap() is that characters are not allways with the same size ... I mean ok if the text is like ( WWWWW ) then i know that i have to break it one the 5th letter BUT what if the text is like ( iiiiii ) ? then its not the same lenght.

          look what happens if for example i break thiese texts on the 5th letter

          WWWWW
          WWWWW
          WWWWW

          Looks fine
          BUT :

          iiiii iiiii iiiii
          iiiii iiiii iiiii
          iiiii iiiii iiiii

          is there any way to break the text using the lenght.. for example : wrap the text exactly where it gets longer than 200 pixels

          So i think the CSS command will work better but as you said its not supported by all browsers

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            You could try using a font where all characters are equally wide, like say 'Courier New'.

            I'd be very careful if using a CSS property that has as little support as the word-break: break-all property. It may cause more problems than it solves.

            Comment

            • bnashenas1984
              Contributor
              • Sep 2007
              • 257

              #7
              Thanks again for your help..
              Thats a good idea to use a font with the same size characters. I will use something like this on my website but there must be a way to use another fonts...
              I mean i'v seen more than thusands of websites which show users text,profile and many things which contain texts entered by users and not only with these kind of fonts..

              Anyways I'll send a reply as soon as i get any answer for this question

              Thanks again for your help

              Comment

              Working...