Home > Article > Backend Development > PHP's chunk_split() function
This article introduces to you the chunk_split() function of PHP. Now I share it with you. Friends in need can refer to it
#The chunk_split() function splits a string into a series of smaller parts.
Note: This function does not change the original string.
chunk_split(string,length,end)
Description | |
---|---|
Required. Specifies the string to be split. | |
Optional. A number defining the length of the string block. Default is 76. | |
Optional. A string defining what is placed after each string block. Default is \r\n. |
Return value: | Returns the split string. |
---|---|
PHP version: | 4 |
在每个字符后分割一次字符串,并在每个分割后添加 ".":
源代码:
<!DOCTYPE html> <html> <body>
<?php $str = "Hello world!"; echo chunk_split($str,1,"."); ?> </body> </html>
运行结果:
H.e.l.l.o. .w.o.r.l.d.!.
在每六个字符后分割一次字符串,并在每个分割后添加 "...":
源代码:
<!DOCTYPE html> <html> <body>