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()函数使用的更多相关文章

  1. php wordwrap()函数 语法

    php wordwrap()函数 语法 wordwrap()函数怎么用? wordwrap()函数表示按照指定长度对字符串进行折行处理,语法是wordwrap(string,width,break,c ...

  2. PHP wordwrap() 函数

    实例 按照指定长度对字符串进行折行处理: <?php高佣联盟 www.cgewang.com$str = "An example of a long word is: Supercal ...

  3. OC与c混编实现Java的String的hashcode()函数

    首先,我不愿意大家需要用到这篇文章里的代码,因为基本上你就是被坑了. 起因:我被Java后台人员坑了一把,他们要对请求的参数增加一个额外的字段,字段的用途是来校验其余的参数是否再传递过程中被篡改或因为 ...

  4. string类find函数返回值判定

     string类find函数返回值判定 代码示例 #include<iostream> #include<cstring> using namespace std; int m ...

  5. C string.h 常用函数

    参考:http://womendu.iteye.com/blog/1218155 http://blog.csdn.net/zccst/article/details/4294565 还有一些,忘记了 ...

  6. c++中string的常用函数说明

    string可以说是是字符数组的升级版,使用更加啊方便,不容易出错.本文对string的常用函数进行简单介绍,做到会用即可. string中的常用函数分为四类,即赋值,添加,比较和删除. 一.赋值 1 ...

  7. C++ string类及其函数的讲解

    文章来源于:http://www.cnblogs.com/hailexuexi/archive/2012/02/01/2334183.html C++中string是标准库中一种容器,相当于保存元素类 ...

  8. PHP之string之explode()函数使用

    explode (PHP 4, PHP 5, PHP 7) explode - Split a string by string explode - 使用一个字符串分割另一个字符串 Descripti ...

  9. C++string类常用函数

    C++string类常用函数 string类的构造函数:string(const char *s);    //用c字符串s初始化string(int n,char c);     //用n个字符c初 ...

随机推荐

  1. Oracle Inventory Management Application Program Interface ( APIs) (Doc ID 729998.1)

    In this Document Goal Solution References APPLIES TO: Oracle Inventory Management - Version 12.0.0 a ...

  2. TSQL--SQL SERVER 常用系统变量

    ----------全局变量select @@version as '版本';---------------------------返回当前数据库的版本信息 select APP_NAME ( ) a ...

  3. win32拖拽编程

    本文由作者邹启文授权网易云社区发布. 在邮箱大师PC版中,我们需要实现一个功能:账号和邮件夹拖拽排序. 准备 封装win32 API.我们使用到的API有, ImageList_Create.Imag ...

  4. c++11新特性总结(转。加上重点)

    1.类型与变量相关 1.1.nullptr: 取代了NULL,专用于空指针 1.2.constexpr: 近似const, 可以修饰变量,也可以修饰函数, 修饰变量如: const int globa ...

  5. SQL语句优化 (一) (52)

    优化SQL语句的一般步骤 1 通过show status命令了解各种SQL的执行频率. 格式:mysql> show [session|global]status; 其中:session(默认) ...

  6. c++实验5 顺序/链式队列

    链式队列及循环队列 1.循环队列的实现(请采用模板类及模板函数实现) [实现提示] 同时可参见教材p65-p67页的ADT描述及算法实现及ppt)函数.类名称等可自定义,部分变量请加上学号后3位.也可 ...

  7. 【OCP-12c】CUUG 071题库考试原题及答案解析(15)

    15.(6-24)choose the best answerExamine the structure of the MEMBERS table:You want to display detail ...

  8. 前端切图要选择png和jpg呢?

    今天特意验证了一下: 切完图分别保存png24.png8和jpg60.jpg80(60和80表示保存图片时品质选择)后, 然后再压缩图片,压缩图片地址:https://tinypng.com/ 图片直 ...

  9. HDP Spark2 HIVE3.1 的问题

    HDP 上安装了 Hive3.1 和 Spark2, 提交 Spark 作业时,报找不到 Hive 中表的问题 但是查一了下 hive 表,明明是存在这个表的.查看日志,注意到如下的一段日志. 没修改 ...

  10. 【性能分析】使用Intel VTune Amplifier

    本文转自 https://software.intel.com/zh-cn/blogs/2010/11/10/amplxe-cl/版权归原作者所有,如原作者有任何不允许转载之理由,本文将自行删除. I ...