Hallo,
ich hab ein Problem mit dem Zeilenumbruch.
Gibt es eine Funktion in PHP bzw. eine Klasse o.ä. mit deren Hilfe ich in einem String Zeilenumbrüche einfügen kann?
gruß
sd
Wiedmann wrote::?:
Also irgenwie hab ich jetzt dein Problem nicht verstanden. Dir geht es doch nicht um so etwas triviales wie "\n"?
<?PHP
$string="Ich bin ein ganz blöder String der viel zu lange ist das er in eine Zeile passt";
$rest=$string;
$max_lange=20;
for($x=0;$x<100;$x++) //Sicherheitshalber
{
if(strlen($rest)<=$max_lange)
{
$output[$x]=$rest;
break;
}
$output[$x]=substr($rest,0,strrpos(substr($rest,0,$max_lange)," "));
$rest=substr($rest,strrpos(substr($rest,0,$max_lange)," ")+1,strlen($rest));
}
foreach ($output as $buffer) {
echo "$buffer\n";
}
?>
function ImageStringWrap($image, $font, $x, $y, $text, $color, $maxwidth)
{
$fontwidth = ImageFontWidth($font);
$fontheight = ImageFontHeight($font);
if ($maxwidth != NULL) {
$maxcharsperline = floor($maxwidth / $fontwidth);
$text = wordwrap($text, $maxcharsperline, "\n", 1);
}
$lines = explode("\n", $text);
while (list($numl, $line) = each($lines)) {
ImageString($image, $font, $x, $y, $line, $color);
$y += $fontheight;
}
}
Users browsing this forum: No registered users and 22 guests