I need to create a PHP function which takes a long paragraph and at 40 characters breaks to a new line. The catch is it should not break at exactly 40 characters because that would create obvious issues.
How would i make it so it breaks at the closest separator(.,:?!) to the 40 character mark?
Edit: The code from the thread @NicoHaase mentioned Format string after closest separator
had this snippet
$WidgetText = substr($string, 0, strrpos(substr($string, 0, 200), '.'));
which is about as far as i got to finding a solution when i searched myself. What i am wondering now is how should i modify it to break at every 40 characters?