好吧,它可以工作,但我只想打破超过特定长度的单-6ren">
gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 21:06:50 25 4
gpt4 key购买 nike

我正在尝试使用 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个字符

最佳答案

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

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

它默认为 false(不要打断长单词)。

关于php - wordwrap()... 只打破特定长度的单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30988272/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com