<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >wordwrap</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="String 字符串处理函数" HREF="ref.strings.html"><LINK REL="PREVIOUS" TITLE="vsprintf" HREF="function.vsprintf.html"><LINK REL="NEXT" TITLE="Shockwave Flash Functions" HREF="ref.swf.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP 手册</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.vsprintf.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="ref.swf.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.wordwrap" ></A >wordwrap</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN228915" ></A ><P > (PHP 4 >= 4.0.2, PHP 5)</P >wordwrap -- Wraps a string to a given number of characters using a string break character </DIV ><DIV CLASS="refsect1" ><A NAME="AEN228918" ></A ><H2 >Description</H2 >string <B CLASS="methodname" >wordwrap</B > ( string str [, int width [, string break [, bool cut]]] )<BR ></BR ><P > Returns a string with <CODE CLASS="parameter" >str</CODE > wrapped at the column number specified by the optional <CODE CLASS="parameter" >width</CODE > parameter. The line is broken using the (optional) <CODE CLASS="parameter" >break</CODE > parameter. </P ><P > <B CLASS="function" >wordwrap()</B > will automatically wrap at column 75 and break using '<TT CLASS="literal" >\n</TT >' (newline) if <CODE CLASS="parameter" >width</CODE > or <CODE CLASS="parameter" >break</CODE > are not given. </P ><P > If the <CODE CLASS="parameter" >cut</CODE > is set to <TT CLASS="constant" ><B >TRUE</B ></TT >, the string is always wrapped at the specified width. So if you have a word that is larger than the given width, it is broken apart. (See second example). <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B > The optional <CODE CLASS="parameter" >cut</CODE > parameter was added in PHP 4.0.3 </P ></BLOCKQUOTE ></DIV > </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN228950" ></A ><P ><B >例 1. <B CLASS="function" >wordwrap()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$text </font><font color="#007700">= </font><font color="#DD0000">"The quick brown fox jumped over the lazy dog."</font><font color="#007700">;<br /></font><font color="#0000BB">$newtext </font><font color="#007700">= </font><font color="#0000BB">wordwrap</font><font color="#007700">(</font><font color="#0000BB">$text</font><font color="#007700">, </font><font color="#0000BB">20</font><font color="#007700">, </font><font color="#DD0000">"<br />\n"</font><font color="#007700">);<br /><br />echo </font><font color="#0000BB">$newtext</font><font color="#007700">;<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P > This example would display: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >The quick brown fox<br /> jumped over the lazy<br /> dog.</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN228956" ></A ><P ><B >例 2. <B CLASS="function" >wordwrap()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$text </font><font color="#007700">= </font><font color="#DD0000">"A very long woooooooooooord."</font><font color="#007700">;<br /></font><font color="#0000BB">$newtext </font><font color="#007700">= </font><font color="#0000BB">wordwrap</font><font color="#007700">(</font><font color="#0000BB">$text</font><font color="#007700">, </font><font color="#0000BB">8</font><font color="#007700">, </font><font color="#DD0000">"\n"</font><font color="#007700">, </font><font color="#0000BB">true</font><font color="#007700">);<br /><br />echo </font><font color="#DD0000">"$newtext</font><font color="#007700">\n</font><font color="#DD0000">"</font><font color="#007700">;<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P > This example would display: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >A very long wooooooo ooooord.</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P > See also <A HREF="function.nl2br.html" ><B CLASS="function" >nl2br()</B ></A > and <A HREF="function.chunk-split.html" ><B CLASS="function" >chunk_split()</B ></A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.vsprintf.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >起始页</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="ref.swf.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >vsprintf</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.strings.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Shockwave Flash Functions</TD ></TR ></TABLE ></DIV ></BODY ></HTML >