Saturday, August 9, 2008

Split Long Line in PHP

//Split the Long line
function Long_PadString($String, $max_chars = 12){
$Exploded = explode(" ", $String);
$Max_Parts = count($Exploded);

$CurArray = 0;
$OutString = '';
while($CurArray<=$Max_Parts)
{
$Peice_Size = strlen($Exploded[$CurArray]);
if($Peice_Size>15)
{
$OutString .= chunk_split($Exploded[$CurArray], $max_chars, " ");
$CurArray++;
} else {
$OutString .= " ".$Exploded[$CurArray];
$CurArray++;
}
}

return $OutString;
}

/* Example for Long_PadString */
$text = "dfsdfsdfdsfdfsdfsdfdsfdfsdfsdfdsfdfsdfsdfdsfdfsdfsdfdsfdfsdfsdfdsfdfsdfsdfdsfdfsdfsdfdsfdfsdfsdfdsfdfsdfsdfdsfdfsdfsdfdsfdfsdfsdfdsfdfsdfsdfdsfdfsdfsdfdsfdfsdfsdfdsfdfsdfsdfdsfdfsdfsdfdsfdfsdfsdfdsfdfsdfsdfdsfdfsdfsdfdsfdfsdfsdfdsfdfsdfsdfdsfdfsdfsdfdsfdfsdfsdfdsfdfsdfsdfdsf";
echo Long_PadString($text, 20);

No comments:

Popular Posts