string wrap
String Breaking
function Long_String_Break($string,$length)
{
if($string!='')
{
$new_string = explode(' ',$string);
for($i=0;$i<count($new_string);$i++)
{
if(strlen($new_string[$i])>$length)
{
$k=0;
$str = '';
for($j=0;$j<strlen($new_string[$i]);$j++)
{
if($k==$length)
{
$str .= ' ';
$k=0;
}
$str .= $new_string[$i][$j];
$k++;
}
$new_string[$i] = $str;
}
}
return implode(' ',$new_string);
}
else
return;
}
examples:
echo Long_String_Break('hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh',30);
{
if($string!='')
{
$new_string = explode(' ',$string);
for($i=0;$i<count($new_string);$i++)
{
if(strlen($new_string[$i])>$length)
{
$k=0;
$str = '';
for($j=0;$j<strlen($new_string[$i]);$j++)
{
if($k==$length)
{
$str .= ' ';
$k=0;
}
$str .= $new_string[$i][$j];
$k++;
}
$new_string[$i] = $str;
}
}
return implode(' ',$new_string);
}
else
return;
}
examples:
echo Long_String_Break('hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh',30);
string wrap
function mywordwrap($string)
{
$length = strlen($string);
for ($i=0; $i<=$length; $i=$i+1)
{
$char = substr($string, $i, 1);
if ($char == "<")
$skip=1;
elseif ($char == ">")
$skip=0;
elseif ($char == " ")
$wrap=0;
if ($skip==0)
$wrap=$wrap+1;
$returnvar = $returnvar . $char;
if ($wrap>30) // alter this number to set the maximum word length
{
$returnvar = $returnvar . "<br>";
$wrap=0;
}
}
return $returnvar;
}
{
$length = strlen($string);
for ($i=0; $i<=$length; $i=$i+1)
{
$char = substr($string, $i, 1);
if ($char == "<")
$skip=1;
elseif ($char == ">")
$skip=0;
elseif ($char == " ")
$wrap=0;
if ($skip==0)
$wrap=$wrap+1;
$returnvar = $returnvar . $char;
if ($wrap>30) // alter this number to set the maximum word length
{
$returnvar = $returnvar . "<br>";
$wrap=0;
}
}
return $returnvar;
}
Permissions in this forum:
You cannot reply to topics in this forum
Fri Jul 22, 2011 1:37 pm by shyamsunder
» Thousands of Free PHP Scripts Recommended
Wed May 18, 2011 10:33 am by bizboy12
» PHP form validation problem?
Wed Jan 12, 2011 1:25 pm by simy202
» string wrap
Sat Aug 02, 2008 2:06 pm by scvinodkumar
» retrieving current date rows
Tue Jul 15, 2008 3:25 am by scvinodkumar
» number in words
Tue Apr 29, 2008 3:10 pm by scvinodkumar
» Simple PHP Form Field Generator
Fri Apr 25, 2008 12:28 pm by scvinodkumar
» PHP password generator
Fri Apr 18, 2008 7:24 pm by scvinodkumar
» PHP Script to Extract Email Address from any text
Fri Apr 18, 2008 7:18 pm by scvinodkumar