<?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.11 $ --> <!-- splitted from ./en/functions/strings.xml, last change in rev 1.142 --> <refentry id="function.wordwrap"> <refnamediv> <refname>wordwrap</refname> <refpurpose> Wraps a string to a given number of characters using a string break character. </refpurpose> </refnamediv> <refsect1> <title>Description</title> <methodsynopsis> <type>string</type><methodname>wordwrap</methodname> <methodparam><type>string</type><parameter>str</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>width</parameter></methodparam> <methodparam choice="opt"><type>string</type><parameter>break</parameter></methodparam> <methodparam choice="opt"><type>boolean</type><parameter>cut</parameter></methodparam> </methodsynopsis> <para> Returns a string with <parameter>str</parameter> wrapped at the column number specified by the optional <parameter>width</parameter> parameter. The line is broken using the (optional) <parameter>break</parameter> parameter. </para> <para> <function>wordwrap</function> will automatically wrap at column 75 and break using '<literal>\n</literal>' (newline) if <parameter>width</parameter> or <parameter>break</parameter> are not given. </para> <para> If the <parameter>cut</parameter> is set to 1, 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). <note> <para> The optional <parameter>cut</parameter> parameter was added in PHP 4.0.3 </para> </note> </para> <example> <title><function>wordwrap</function> example</title> <programlisting role="php"> <![CDATA[ <?php $text = "The quick brown fox jumped over the lazy dog."; $newtext = wordwrap($text, 20, "<br />\n"); echo $newtext; ?> ]]> </programlisting> <para> This example would display: </para> <screen> <![CDATA[ The quick brown fox<br /> jumped over the lazy<br /> dog. ]]> </screen> </example> <example> <title><function>wordwrap</function> example</title> <programlisting role="php"> <![CDATA[ <?php $text = "A very long woooooooooooord."; $newtext = wordwrap($text, 8, "\n", 1); echo "$newtext\n"; ?> ]]> </programlisting> <para> This example would display: </para> <screen> <![CDATA[ A very long wooooooo ooooord. ]]> </screen> </example> <para> See also <function>nl2br</function> and <function>chunk_split</function>. </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t indent-tabs-mode:nil sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->