Php > Complete Programs
Wraps text to any desired width with customizable line break
Wraps text to any desired width with customizable line break \n'){ $len = strlen($text); if ($len > $wrap){ $h = ''; $lastWhite = 0; $lastChar = 0; $lastBreak = 0; while ($lastChar < $len){ $char = substr($text, $lastChar, 1); if (($lastChar - $lastBreak > $wrap) && ($lastWhite > $lastBreak)){ $h .= substr($text, $lastBreak, ($lastWhite - $lastBreak)) . $break; $lastChar = $lastWhite + 1; $lastBreak = $lastChar; } /* You may wish to include other characters as valid whitespace... */ if ($char == ' ' || $char == chr(13) || $char == chr(10)){ $lastWhite = $lastChar; } $lastChar = $lastChar + 1; } $h .= substr($text, $lastBreak); } else{ $h = $text; } return $h; } ?>
Textwrap Example
\n
\n"); for ($w = 80; $w > 0; $w = $w - 10){ $wrapped = textwrap($test, $w); echo( "$w
\n$wrapped
\n
\n"); } ?>
Php Codes
Algorithms
Arrays
Authentication
Calendar
Code Snippets
Programs
Content Manage
Contest Related
Cookies
Credit Cards
DBase Related
Databases
Date Time
Directories
E-Mail
Errors
File
File System
Forms
Handling
Graphics
HTML and PHP
Informix
Ingres
InterBase
LDAP
Look and Feel
Miscellaneous
MySQL
Other
PHP Classes
Searching
Navigation
Statistics
Strings
User Manage