Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function wrapper($stringText, $width){
- $arrayText = explode("\n", $stringText);
- foreach($arrayText as $temp){
- $tempArray[] = explode(" ", $temp);
- }
- var_dump($tempArray);
- $output = "";
- foreach($tempArray as $wordArray){
- $tempString = "";
- $tempOutput = "";
- foreach($wordArray as $word){
- if(strlen($tempString." ".$word) >= $width){
- if(substr($tempString, -1) != "\n"){
- $tempString .= "\n";
- }
- $tempOutput .= $tempString;
- $tempString = $word;
- }else{
- if($tempString == ''){
- $tempString = $word;
- }else{
- $tempString .= " ".$word;
- }
- }
- }
- $output .= $tempOutput.$tempString;
- }
- return $output;
- }
- $string = <<<END
- here's some text
- I hope you enjoy it there shouldn't be too many problems with it
- but if there is don't come winging
- END;
- echo wrapper($string, 20);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment