本文介紹了str_split 沒有自動(dòng)換行的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
我正在尋找最快的解決方案,以拆分 一個(gè)字符串分成幾部分,沒有 自動(dòng)換行.
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");
推薦答案
你其實(shí)可以使用 wordwrap()
,輸入到 explode()
中,使用換行符
作為分隔符.explode()
將在 wordwrap()
產(chǎn)生的換行符上拆分字符串.
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"
}
這篇關(guān)于str_split 沒有自動(dòng)換行的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!