wordwrap()

Creator:
Virst
Description:
Learn how to wrap text

Two wrap a string you use the function wordwrap(): wordwrap("text", width, "line separator", cut); Example:



<?php 
    $string 
"Hello! This is a really cool function."
    
$wordwrap wordwrap($string6""); 
    echo 
$wordwrap
?>

This will output:

-------
Hello!
This
is a
really
cool
function
.
-------

Notice that each line is about 6 characters long, UNLESS a word is longer than six characters. If you want the function to cut long words in half to fit NO MORE than six characters, put a '1' in the fourth parameter.

Example:



<?php 
    $string 
"Hello! This is a really cool function."
    
$wordwrap wordwrap($string6"",1); 
    echo 
$wordwrap
?> 

Comments

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <b> <u> <i> <hr> <img src <url=
  • Lines and paragraphs break automatically.

More information about formatting options