<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"<br>n",TRUE);
?>
Copy after login
实例 2
对字符串进行折行:
<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15);
?>
Copy after login
上面代码的 HTML 输出如下(查看源代码):
<!DOCTYPE html>
<html>
<body>
An example of a
long word is:
Supercalifragulistic
</body>
</html>
Copy after login
上面代码的浏览器输出如下:
An example of a long word is: Supercalifragulistic
Copy after login
wordwrap()函数可以按照指定的固定行长度格式化文本段落,让段落看起来更加整齐
<?php
$string = "TRADING ON MARGIN POSES ADDITIONAL
RISKS AND IS NOT SUITABLE FOR ALL
INVESTORS.
A COMPLETE LIST OF THE RISKS ASSOCIATED WITH MARGIN TRADING IS
AVAILABLE IN THE MARGIN RISK DISCLOSURE DOCUMENT.";
$string = str_replace("\n", " ", $string);
$string = str_replace("\r", " ", $string);
print(wordwrap($string, 40)."\n");
?>
Copy after login
上面的代码返回如下结果
TRADING ON MARGIN POSES ADDITIONAL
RISKS AND IS NOT SUITABLE FOR ALL
INVESTORS. A COMPLETE LIST OF THE
RISKS ASSOCIATED WITH MARGIN TRADING IS
AVAILABLE IN THE MARGIN RISK DISCLOSURE
DOCUMENT.
Copy after login
The above is the detailed content of PHP function wordwrap() that wraps strings according to the specified length. For more information, please follow other related articles on the PHP Chinese 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