2015-06-22 48 views
3

我想用wordwrap()打破文本,但我不希望它在每次達到特定長度時都會破壞文本,我希望它打破只有超過任何特定的長度,例如詞: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

耳鼻喉科,這個詞有13個字符

+1

你能發佈你想要的預期結果嗎? – cmo

+0

這個問題很不清楚。當'$ cut'(最後一個參數)被設置爲'false'(這是默認值)時,PHP不會分割長字。如果你想打破這個詞,請將它設置爲「true」。 – DanFromGermany

+0

當我設置最大寬度爲100像素,例如,並回顯任何大字,單詞超過寬度,這就是爲什麼我想分裂只有特定的字 –

回答

2

使用最後一個參數$cut削減長的話:

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

它默認爲false(不要打破長期工作DS)。