Jump to: navigation, search

Php wordwrap

From w3cyberlearnings

Contents

PHP function wordwrap

This function wraps a string to a given number of characters.

Syntax wordwrap

  • string: string input
  • width: the maximum length of the string to be splited into, default value is 75
  • break: specifies the characters to be used.
  • 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
wordwrap(string,width,break,cut);

Example 1

<?php
$str = "I work my way up to the top.";

echo wordwrap($str,5,'<br/>');

?>

Output

I<br/>work<br/>my<br/>way<br/>up to<br/>the<br/>top.

Example 2

<?php
$str = "Take care Kimalionaka";

echo wordwrap($str,5,'<br/>',TRUE);

?>

Output

Take
care
Kimal
ionak
a

Example 2: HTML Output

Take<br/>care<br/>Kimal<br/>ionak<br/>a

Related Functions


Navigation
Web
SQL
MISC
References