Jump to content

Make a new line at a certain point


Shadow Hatake

Recommended Posts

Olay, so I'm making a chat box in an iamge and I want the line to stop at a certain point and make a new line. How would I do this?

Here's my code. It's currently untested due to my hosting being down.

[code]<?php

include('dbconnect.php');

$height = 150;
$width = 400;
$background = 'http://www.infected-designs.com/chatbox/chatbox.png';
$im = imagecreatefrompng($background);
$white = imagecolorallocate( $im, 255, 255, 255 );
$x = 32;

$query = "SELECT * FROM chatbox ORDER BY id ASC";
$result = mysql_query( $query );

while( $row = @mysql_fetch_array( $result, MYSQL_ASSOC ) ) {
imagestring( $im, 2, 7, $x, $row['name'].': '.$row['message'], $white );
$x = $x + 15;
}

header('Content-Type: image/png');
imagepng($im);
?>[/code]
Link to comment
Share on other sites

You may want to use the wordwrap function.  It will wrap your string at a certain number of characters using a specified break character...\n, \r, \r\n...even <br />.  You can force it to either break at exactly that number of characters, or at the closest word to that number...like a word processor.

http://www.php.net/wordwrap
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.