The wordwrap() function in PHP 8.5 works exactly the same as in previous versions. It wraps a string to a given number of characters using a break character.
Basic Example 1:
<?php
$text = "The quick brown fox jumped over the lazy dog.";
$newtext = wordwrap($text, 20, "<br /> ");
echo $newtext;
?>
Output:
The quick brown fox<br />
jumped over the lazy<br />
dog.
This wraps the string after approximately 20 characters at word boundaries .
Basic Example 2: Cut Long Words
<?php
$text = "A very long woooooooooooord.";
$newtext = wordwrap($text, 8, " ", true);
echo "$newtext ";
?>
Output:
A very
long
wooooooo
ooooord.