本文介紹了將長字符串分成幾部分 php的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
所以我有一個(gè)大約 3800 個(gè)字符的字符串,它是句子單詞等.
so I have a string which is around 3800 characters, it's sentences words etc.
現(xiàn)在我正在運(yùn)行字符串,雖然限制是 1000,那么我怎么能把字符串分成 4 段,每段最多包含 1000 個(gè)字符,而不是把單詞分成兩半,有什么辦法嗎?
Now I'm running the string through something although the limit is 1000, so how could I break the string into 4 pieces each containing a maximum of 1000 characters and not breaking words in half, is there any way to do it?
謝謝
推薦答案
您可以使用 str_split
.
$string = "the_long_string";
$array = str_split($string, 1000); //$array will contain elements which each is 1000 chars long.
如果你想讓單詞不被截?cái)啵诮財(cái)嗨鼈冎巴ㄟ^wordwrap
進(jìn)行轉(zhuǎn)換
if you want words not to cut off transform it through wordwrap
prior to cutting them as follows
$string = "the_long_string";
$string = wordwrap($string, 1000, "||"); //assume your string doesn't contain `||`
$parts = explode("||", $string);
這篇關(guān)于將長字符串分成幾部分 php的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!