Bloodrun Posted March 19, 2009 Report Share Posted March 19, 2009 I've about run my course with luck, and i'm nearing the verge of insanity. I need help with these, codes. I've asked around so many different places, each only adding a little insight here and there. I know this is one of the most, if not the most ridiculous places to post this question, but at least it's better then doing nothing. I have this text wrap code, that works, but lacks the ability to resize chunks of text, which I need it too. [spoiler=textwrap] <?php function justify($text, $width, $break) { $marker = "__$%@random#$()__"; // lines is an array of lines containing the word-wrapped text $wrapped = wordwrap($text, $width, $marker); $lines = explode($marker, $wrapped); $result = ""; foreach ($lines as $line_index=>$line) { $line = trim($line); $words = explode(" ", $line); $words = array_map("trim", $words); $wordcount = count($words); $wordlength = strlen(implode("", $words)); if (3*$wordlength < 2*$width) { // don't touch lines shorter than 2/3 * width continue; } $spaces = $width - $wordlength; $index = 0; do { $words[$index] = $words[$index] . " "; $index = ($index + 1) % ($wordcount - 1); $spaces--; } while ($spaces>0); $lines[$line_index] = implode("", $words); } return implode($break, $lines); } ?> Again, I know it's the worst idea to post here, but who knows, maybe theres some random viewer who knows php -.-" Link to comment Share on other sites More sharing options...
Holy Babylon Posted March 19, 2009 Report Share Posted March 19, 2009 $spaces = $width - $wordlength; $index = 0; Should that be in brackets or something? Because it isn't. Link to comment Share on other sites More sharing options...
Jesus Posted March 19, 2009 Report Share Posted March 19, 2009 This doesn't look like Visual Basic.. *cringes* I can't doanything else besides that, havn't taken a class on anything else yet.. XD. Sorry. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.