wordwrap()...只打破特定长度的单词

时间:2015-06-22 19:30:43

标签: php

我试图使用wordwrap()来破解文字,但我不想让它在每次达到特定长度时打破文本,我希望它只打破单词超过任何特定长度,例如:

<?php

$string = "Some text that will be splited each 15 characters...";
echo wordwrap($string,15,"<br>");
?>

嗯,它有效,但我只想打破超过特定长度的单词,例如:

<?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...
?>

我该怎么办?谢谢!

我的预期结果是:

此字符串包含Entertainm字样

ent,这个单词有13个字符

1 个答案:

答案 0 :(得分:2)

使用最后一个参数$cut剪切长词:

wordwrap($string, 10, "<br>", true); // true in the last param cuts long words

默认为false(不要破坏长词)。