Main Menu
Home
About Us
Contact Us
Careers
Client Login
Solutions
Products
Web Design
IT Services
DB Development
Quickhelp
PHP Examples
Mail Clients
Linux
Links


Client Login





Lost Password?

 

Knowledge Base
For quick help and some common problems, please see our knowledge base.
Latest News

Home arrow PHP Examples arrow String Manipulation arrow Wrap a long string/word
Wrap a long string/word Print E-mail

As name states, wordwrap is handy function that wraps long words over multiple lines. There are occasions when a particular word is just too long and goes outside of provided space. (See wikipedia for longest words)

string wordwrap ( string source [, int width
[, string break [, boolean cut]]])

Example 1: Wrapping full words

<?php
$text = "Word wrap will split this text up into smaller lines, which
 makes for easier reading and neater layout.";
 $text = wordwrap($text, 20, "");
 print $text;
 ?>
 

Result:

Word wrap will split
this text up into
smaller lines, which
makes for easier
reading and neater
layout.

If you wish to break long words, use the example below. The line will be wrapped after 6th character in the line:

Example 2: Breaking long words

<?php
   $text = "Micro-organism is a very long word.";
   $text = wordwrap($text, 6, "\n", 1);
   print $text;
?>
 

Result:

Micro-
organi
sm is
a very
long
word.