Home >Backend Development >PHP Tutorial >PHP's chunk_split() function

PHP's chunk_split() function

不言
不言Original
2018-04-13 10:13:492094browse

This article introduces to you the chunk_split() function of PHP. Now I share it with you. Friends in need can refer to it


Definition and usage


#The chunk_split() function splits a string into a series of smaller parts.

Note: This function does not change the original string.



## Grammar

chunk_split(string,length,end)



##Parametersstringlengthend

Technical details

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





实例 1


在每个字符后分割一次字符串,并在每个分割后添加 ".":

源代码:

<!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.!.

实例 2


在每六个字符后分割一次字符串,并在每个分割后添加 "...":

源代码:

<!DOCTYPE html>
<html>
<body>

  



运行结果:

Hello ...world!...

Related recommendations:

php splits a string into a series of smaller parts function chunk_split()

10 recommended articles about the string function chunk_split()

chunk_split( in php ) function usage introduction

The above is the detailed content of PHP's chunk_split() function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn