Title: Safe Wordwrap Marked Cool (Review this resource) Author: kailash Posted On: 2005-02-09 Category: Home > PHP Functions
Popularity:
Description: A substitute for PHP's default wordwrap() function. This function doesn't touch HTML tags, but text.
Total Hits: 808 Total Votes: 0
Total Points: 0 (1 reviews)
Page Navigation: [1]
Safe WORD wrap function
<?php
/* Safe
WORD wrap function This doesn't
touch HTML tags
Coded
by Kailash Nadh http://kailashnadh.name
This
code was written for 'boastMachine' http://boastology.com
USAGE:
------
bmc_wordwrap(STRING,WARP_LENGTH,DIVIDER);
eg: bmc_wordwrap("text
here",80,"<br />");
*/
function bmc_wordwrap($str, $cols=80, $cut="\n")
{
global $bmc_vars;
$len
= strlen($str); $tag = 0; $wordlen=0; $result=null;
for
($i = 0; $i < $len; $i++) { $chr
= $str[$i]; if
($chr == '<' || $chr == '&') { $tag++; }
elseif ($chr == '>' || $chr == ';') { $tag--; }
elseif ((!$tag) && (ctype_space($chr))) { $wordlen
= 0; }
elseif (!$tag) { $wordlen++; }
if
((!$tag) && ($wordlen) && (!($wordlen % $cols))) { $chr
.= $cut; }
$result
.= $chr; }
return
$result; }
?>
Page Navigation: [1]
|