Jump to content


Photo

Make a new line at a certain point


  • Please log in to reply
9 replies to this topic

#1 Shadow Hatake

Shadow Hatake
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 19 July 2006 - 01:08 AM

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.

<?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);
?>


#2 Shadow Hatake

Shadow Hatake
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 20 July 2006 - 01:27 AM

Ack. 3rd page and no replies. :(

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 20 July 2006 - 01:35 AM

you have to wait your turn read the forum rules ok.


and the ansaw to this is \n meaning new line.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 20 July 2006 - 01:40 AM

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

#5 Shadow Hatake

Shadow Hatake
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 20 July 2006 - 01:47 AM

Alright I tried that and it didn't work so I decided to try a test.

<?php

$test = "this is a test string";
$test2 = wordwrap( $test, 4 );

echo $test2;

?>

and it won't wrap.

http://www.infected-...hatbox/test.php

#6 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 20 July 2006 - 01:54 AM

Actually, it did work.  Do a view source on your page.

Remember, line breaks are not displayed in html.  Put <pre> tags around your echo, or force it to use <br /> as the break character.

#7 Shadow Hatake

Shadow Hatake
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 20 July 2006 - 01:57 AM

Oh okay. So how would I do this with an image?

#8 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 20 July 2006 - 01:58 AM

imagestring( $im, 2, 7, $x, wordwrap($row['name'].': '.$row['message'], 20, "\n"), $white );


#9 Shadow Hatake

Shadow Hatake
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 20 July 2006 - 02:01 AM

okay I tried that and it add's yen signs where the breaks should be...

http://www.infected-...box/chatbox.php

#10 Shadow Hatake

Shadow Hatake
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 20 July 2006 - 08:48 PM

Bump.  ;D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users