本文介紹了str_split 沒有自動換行的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在尋找最快的解決方案,以拆分 一個字符串分成幾部分,沒有 自動換行.
I'm looking for the fastest solution, to split a string into parts, without word-wrap.
$strText = "The quick brown fox jumps over the lazy dog";
$arrSplit = str_split($strText, 12);
// result: array("The quick br","own fox jump","s over the l","azy dog");
// better: array("The quick","brown fox","jumps over the","lazy dog");
推薦答案
你其實可以使用 wordwrap()
,輸入到 explode()
中,使用換行符
作為分隔符.explode()
將在 wordwrap()
產生的換行符上拆分字符串.
You actually can use wordwrap()
, fed into explode()
, using the newline character
as the delimiter. explode()
will split the string on newlines produced by wordwrap()
.
$strText = "The quick brown fox jumps over the lazy dog";
// Wrap lines limited to 12 characters and break
// them into an array
$lines = explode("
", wordwrap($strText, 12, "
"));
var_dump($lines);
array(4) {
[0]=>
string(9) "The quick"
[1]=>
string(9) "brown fox"
[2]=>
string(10) "jumps over"
[3]=>
string(12) "the lazy dog"
}
這篇關于str_split 沒有自動換行的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!