PHP之string之wordwrap()函数使用
wordwrap
- (PHP 4 >= 4.0.2, PHP 5, PHP 7)
- wordwrap — Wraps a string to a given number of characters
- wordwrap — 打断字符串为指定数量的字串
Description
string wordwrap (
string $str [,
int $width = 75 [,
string $break = "\n" [,
bool $cut = FALSE ]]]
)
//Wraps a string to a given number of characters using a string break character.
//使用字符串断点将字符串打断为指定数量的字串。
Parameters
str
- The input string.
- 输入字符串。
width
- The number of characters at which the string will be wrapped.
- 列宽度。
break
- The line is broken using the optional break parameter.
- 使用可选的
break参数打断字符串。
cut
- If the cut is set to TRUE, the string is always wrapped at or before the specified width. So if you have a word that is larger than the given width, it is broken apart. (See second example). When FALSE the function does not split the word even if the width is smaller than the word width.
- 如果 cut 设置为
TRUE,字符串总是在指定的width或者之前位置被打断。因此,如果有的单词宽度超过了给定的宽度,它将被分隔开来。(参见第二个范例)。 当它是FALSE,函数不会分割单词,哪怕 width 小于单词宽度。
Return Values
- Returns the given string wrapped at the specified length.
- 返回打断后的字符串。
Examples
<?php
/**
* Created by PhpStorm.
* User: zhangrongxiang
* Date: 2018/3/8
* Time: 下午9:27
*/
$text = "The quick brown fox jumped over the lazy dog.";
$newtext = wordwrap( $text, 20, "\n" );
//The quick brown fox
//jumped over the lazy
//dog.
echo $newtext . PHP_EOL;
$text = "A very long woooooooooooord.";
$newtext = wordwrap( $text, 8, "\n", false );
//A very
//long
//woooooooooooord.
echo $newtext . PHP_EOL;
$newtext = wordwrap( $text, 8, "\n", true );
//A very
//long
//wooooooo
//ooooord.
echo $newtext . PHP_EOL;
$str = "hello world hello php";
//hello-world-hello-php
echo wordwrap( $str, 5, "-", false ) . PHP_EOL;
//hello world hello php
echo wordwrap( $str ) . PHP_EOL;
//hello
//world
//hello
//php
echo wordwrap( $str, 3 ) . PHP_EOL;
See
All rights reserved
PHP之string之wordwrap()函数使用的更多相关文章
- php wordwrap()函数 语法
php wordwrap()函数 语法 wordwrap()函数怎么用? wordwrap()函数表示按照指定长度对字符串进行折行处理,语法是wordwrap(string,width,break,c ...
- PHP wordwrap() 函数
实例 按照指定长度对字符串进行折行处理: <?php高佣联盟 www.cgewang.com$str = "An example of a long word is: Supercal ...
- OC与c混编实现Java的String的hashcode()函数
首先,我不愿意大家需要用到这篇文章里的代码,因为基本上你就是被坑了. 起因:我被Java后台人员坑了一把,他们要对请求的参数增加一个额外的字段,字段的用途是来校验其余的参数是否再传递过程中被篡改或因为 ...
- string类find函数返回值判定
string类find函数返回值判定 代码示例 #include<iostream> #include<cstring> using namespace std; int m ...
- C string.h 常用函数
参考:http://womendu.iteye.com/blog/1218155 http://blog.csdn.net/zccst/article/details/4294565 还有一些,忘记了 ...
- c++中string的常用函数说明
string可以说是是字符数组的升级版,使用更加啊方便,不容易出错.本文对string的常用函数进行简单介绍,做到会用即可. string中的常用函数分为四类,即赋值,添加,比较和删除. 一.赋值 1 ...
- C++ string类及其函数的讲解
文章来源于:http://www.cnblogs.com/hailexuexi/archive/2012/02/01/2334183.html C++中string是标准库中一种容器,相当于保存元素类 ...
- PHP之string之explode()函数使用
explode (PHP 4, PHP 5, PHP 7) explode - Split a string by string explode - 使用一个字符串分割另一个字符串 Descripti ...
- C++string类常用函数
C++string类常用函数 string类的构造函数:string(const char *s); //用c字符串s初始化string(int n,char c); //用n个字符c初 ...
随机推荐
- NTLM认证协议及SSPI的NTLM实现
没错,NTLM就是你听说过的那个NTLM.是微软应用最广泛的认证协议之一. NTLM是NT LAN Manager的缩写,这也说明了协议的来源.NTLM 是 Windows NT 早期版本的标准安全协 ...
- linux gitlab-ctl reconfigure报错问题修复 502
Running handlers: There was an error running gitlab-ctl reconfigure: bash[migrate gitlab-rails datab ...
- expect+scp传输文件发现文件丢失
背景 使用expect+scp去跨机器传输文件,(别问我为什么,因为公司的测试机器都是通过堡垒机的,无法绕开堡垒机,只能暂时使用这个方法了),结果发现从A传递到B的tar.gz文件大小不一致了的,当时 ...
- hive执行结果moveTask操作失败
hive执行结果moveTask操作失败 Apache Hive 2.1.0 ,在执行"INSERT OVERWRITE TABLE ...... select "或者 " ...
- 如何在TortoiseGit中使用ssh-keygen生成的key
再windows 用TortoiseGit 时,git clone 项目时 提示 "Couldn't load this key (OpenSSH SSH-2 private key),如下 ...
- Visual Studio Code 基本操作 - Windows 版
1.Install the .NET SDK 2.Create app: dotnet new console -o myApp cd myApp 3.Run your app:dotnet run
- webapi中session为null的解决方案
Session webapi中session为null的解决方案 在Global.asax里添加:开启Session功能(默认是不开启) 重写init方法 public class WebApiAp ...
- 文本相似度 余弦值相似度算法 VS L氏编辑距离(动态规划)
设置n为字符串s的长度.("我是个小仙女") 设置m为字符串t的长度.("我不是个小仙女") 如果n等于0,返回m并退出.如果m等于0,返回n并退出.构造两个向 ...
- 决定以后再做公司的项目的时候,能够用其他语言的绝对不用delphi
1.delphi7的IDE真的很不友好 2.delphi7的控件有的有问题 3.delphi7居然不支持结构体的泛型存储 4.网上的解决文档超少,一些小bug,就要折腾半天 5.pascal语法太过结 ...
- ClamAV学习【1】——ClamAV流程
不知道是对还是错,一开始就上手学习ClamAV,享受被虐的过程吧. 发现ClamAV的官网也很少资料,搜商还有待加强,大概翻阅了example的源代码,明白了其查毒的大概方式(BM和AC算法匹配特征码 ...