Home  >  Article  >  Backend Development  >  How to use php wordwrap function

How to use php wordwrap function

藏色散人
藏色散人Original
2019-05-23 13:16:582067browse

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)

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;
?>

Output:

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

php wordwrap() function example 2

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

Output:

you can study php in php.cn

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!

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