Reputation: 467
I'm trying to use wordwrap()
to break the text, but I don't want it to break the text each time it reaches the specific length, I want it to break only the words that exceeds any specific length so for example:
<?php
$string = "Some text that will be splited each 15 characters...";
echo wordwrap($string,15,"<br>");
?>
Well, it works but I'd like to break only words that exceeded specific length for example:
<?php
$string = "This string contains word Entertainment, and this word has 13 characters";
//I want the wordwrap to split only the words that exceed the limit so..
wordwrap($string,10,"<br>");
//Wont work as I expect...
?>
What can i do? Thanks!
My expected outcome is :
This string contains word Entertainm
ent, and this word has 13 characters
Upvotes: 3
Views: 507
Reputation: 32340
Use the last parameter $cut
to cut long words:
wordwrap($string, 10, "<br>", true); // true in the last param cuts long words
It defaults to false
(dont break long words).
Upvotes: 2