Introduction to the usage of chunk_split() function in php

WBOY
Release: 2016-07-25 08:58:15
Original
1727 people have browsed it
This article introduces the usage of the chunk_split() function in PHP. Friends in need can refer to it.

Definition and usage chunk_split function splits a string into a series of smaller parts.

Grammar chunk_split(string,length,end)

Parameter Description string required. Specifies the string to be split. length is optional. A number defining the length of the string block. end is optional. A string value that defines what is placed after each string block.

Tips and Notes Note: This function does not change the original string.

Example 1, separate each character and add ".":

<?php
$str = "Hello world!";
echo chunk_split($str,1,".");
//by bbs.it-home.org
?>
Copy after login

Output: H.e.l.l.o. .w.o.r.l.d.!.

Example 2, split the string once after six characters and add "...":

<?php
$str = "Hello world!";
echo chunk_split($str,6,"...");
//by bbs.it-home.org
?>
Copy after login

Output: Hello...world!...



source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!