本文介紹了將長字符串分成幾部分 php的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
所以我有一個大約 3800 個字符的字符串,它是句子單詞等.
so I have a string which is around 3800 characters, it's sentences words etc.
現在我正在運行字符串,雖然限制是 1000,那么我怎么能把字符串分成 4 段,每段最多包含 1000 個字符,而不是把單詞分成兩半,有什么辦法嗎?
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.
如果你想讓單詞不被截斷,在截斷它們之前通過wordwrap
進行轉換
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);
這篇關于將長字符串分成幾部分 php的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!