The string is stored by the db, something like:

YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY

When displaying it displays in one line, and it would be desirable that at least somehow changed, for example:

yyyyyyyyyyyyyyy
yyyyyyyyyyyyyyy
yyyyyyyyyyyyyyy
yyyyyyyyyyyyyyy

How can I do that?

    5 answers 5

    wordwrap :

    $text = "ЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫЫ"; $newtext = wordwrap($text, 8, " ", true); 

      Take strlen (counting characters) and space

       function probel($stroka) { $colvo = strlen($stroka); for ($i = 0; $i <= $colvo; $i++) { if ($j == 15) { $mass .= " "; $j = 0; } else { $mass .= $stroka[$i]; $j++; } } return $mass; } $a = probel('ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss'); print "a - $a<br>"; 

      Ready example. | ^ |

      • By the way, the size of the pieces depends on sha ($ j == number) {} - Hishchnik
      • You do not understand me. - new_russian_man
       echo nl2br($text); 

      Others do not occur ...

        In this case, for web development, it is most acceptable not to pick a string, but simply to set the dimensions of the block in which the string is displayed on the page. If, for example, the string is displayed in a div and you want it to be "not in one line", then just set the div to a limited width!

          if I understand correctly, this will help you:

           $string = preg_replace('/\\r\\n/','<br \/>',$string); echo $sting 

          where $ string is a string from the database