Shadow Hatake Posted July 19, 2006 Share Posted July 19, 2006 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]<?phpinclude('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 https://forums.phpfreaks.com/topic/14995-make-a-new-line-at-a-certain-point/ Share on other sites More sharing options...
Shadow Hatake Posted July 20, 2006 Author Share Posted July 20, 2006 Ack. 3rd page and no replies. :( Link to comment https://forums.phpfreaks.com/topic/14995-make-a-new-line-at-a-certain-point/#findComment-60738 Share on other sites More sharing options...
redarrow Posted July 20, 2006 Share Posted July 20, 2006 you have to wait your turn read the forum rules ok.and the ansaw to this is \n meaning new line. Link to comment https://forums.phpfreaks.com/topic/14995-make-a-new-line-at-a-certain-point/#findComment-60741 Share on other sites More sharing options...
hitman6003 Posted July 20, 2006 Share Posted July 20, 2006 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 https://forums.phpfreaks.com/topic/14995-make-a-new-line-at-a-certain-point/#findComment-60743 Share on other sites More sharing options...
Shadow Hatake Posted July 20, 2006 Author Share Posted July 20, 2006 Alright I tried that and it didn't work so I decided to try a test.[code]<?php$test = "this is a test string";$test2 = wordwrap( $test, 4 );echo $test2;?>[/code]and it won't wrap.http://www.infected-designs.com/chatbox/test.php Link to comment https://forums.phpfreaks.com/topic/14995-make-a-new-line-at-a-certain-point/#findComment-60746 Share on other sites More sharing options...
hitman6003 Posted July 20, 2006 Share Posted July 20, 2006 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. Link to comment https://forums.phpfreaks.com/topic/14995-make-a-new-line-at-a-certain-point/#findComment-60749 Share on other sites More sharing options...
Shadow Hatake Posted July 20, 2006 Author Share Posted July 20, 2006 Oh okay. So how would I do this with an image? Link to comment https://forums.phpfreaks.com/topic/14995-make-a-new-line-at-a-certain-point/#findComment-60751 Share on other sites More sharing options...
hitman6003 Posted July 20, 2006 Share Posted July 20, 2006 [code]imagestring( $im, 2, 7, $x, wordwrap($row['name'].': '.$row['message'], 20, "\n"), $white );[/code] Link to comment https://forums.phpfreaks.com/topic/14995-make-a-new-line-at-a-certain-point/#findComment-60752 Share on other sites More sharing options...
Shadow Hatake Posted July 20, 2006 Author Share Posted July 20, 2006 okay I tried that and it add's yen signs where the breaks should be...http://www.infected-designs.com/chatbox/chatbox.php Link to comment https://forums.phpfreaks.com/topic/14995-make-a-new-line-at-a-certain-point/#findComment-60753 Share on other sites More sharing options...
Shadow Hatake Posted July 20, 2006 Author Share Posted July 20, 2006 Bump. ;D Link to comment https://forums.phpfreaks.com/topic/14995-make-a-new-line-at-a-certain-point/#findComment-61327 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.