Jump to content

force wordwrap a string


astralaaron

Recommended Posts

I want to force a word wrap like this:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Link to comment
Share on other sites

You can force a break after a certain amount of characters with a regular expression. There is also a CSS property but it is not well-implemented.

preg_replace("/([^\s]{100})([^\s])/i", "$1 $2", $string);

Link to comment
Share on other sites

There's already a pre-existing PHP function for it: http://php.net/wordwrapIt's used like this:

<?php$text = "The quick brown fox jumped over the lazy dog.";$newtext = wordwrap($text, 20, "<br />\n");echo $newtext;?>

Which outputs

The quick brown fox<br />jumped over the lazy<br />dog.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...