How to use php wordwrap function

藏色散人
Release: 2023-04-06 18:56:01
Original
2028 people have browsed it

php The wordwrap() function means to wrap a string according to the specified length. The syntax is wordwrap(string,width,break,cut). If the function is successfully executed, the wrapped string will be returned. If it fails, Returns false.

How to use php wordwrap function

How to use the wordwrap() function?

Function: wrap the string according to the specified length

Syntax:

wordwrap(string,width,break,cut)
Copy after login

Parameters:

string Required, specifies the string to be wrapped

width Optional, specifies the maximum line width, the default is 75

break Optional, specifies the use as a separator character (string breaking character), the default is "\n".

cut Optional, specifies whether to wrap words larger than the specified width: false -- default, no-wrap. true -- wrap lines.

Description: If the function is successfully executed, the wrapped string will be returned. If it fails, false will be returned.

php wordwrap() function example 1

<?php
$i = "I love programming. It&#39;s fun.";
$j = wordwrap($i,10,"<br>\n",true);
echo $j;
?>
Copy after login

Output:

I love
programmin
g. It&#39;s
fun.
Copy after login

php wordwrap() function example 2

<?php
$i = "you can study php in php.cn";
$j = wordwrap($i);
echo $j;
?>
Copy after login

Output:

you can study php in php.cn
Copy after login

The above is the detailed content of How to use php wordwrap function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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!