Wrap a string into new lines when it reaches a specific length in PHP

Description

The following code shows how to wrap a string into new lines when it reaches a specific length.

Example


//  w w  w  .  java 2s .  c o  m
<?php
    $str = "An example of a long word is: loooooooooooooooooooooooooong";
    echo wordwrap($str,15,"<br>\n");
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone