sprintlife Posted October 18, 2008 Share Posted October 18, 2008 Hi guys, How would I add line breaks in a line of text? For example I get line of code like this "THE TEXT THE TEXT THE TEXT THE TEXT THE TEXT THE TEXT THE TEXT THE TEXT" and I wanna add a line break after every 8 characters like this. So basically add a /n or <br> after each 8 characters. "THE TEXT THE TEXT THE TEXT THE TEXT THE TEXT THE TEXT THE TEXT THE TEXT" Quote Link to comment https://forums.phpfreaks.com/topic/128956-how-do-i-add-line-breaks/ Share on other sites More sharing options...
zenag Posted October 18, 2008 Share Posted October 18, 2008 $text="THE TEXT THE TEXT THE TEXT THE TEXT THE TEXT THE TEXT THE TEXT THE TEXT"; echo wordwrap($text,8,"<br />\n"); Quote Link to comment https://forums.phpfreaks.com/topic/128956-how-do-i-add-line-breaks/#findComment-668560 Share on other sites More sharing options...
sprintlife Posted October 18, 2008 Author Share Posted October 18, 2008 No way that's how it's done? Wow... This is what I am working with http://www.joaomak.net/util/dtr/. I want to be able to do word warp in images. So would it work Zenag? $text="THE TEXT THE TEXT THE TEXT THE TEXT THE TEXT THE TEXT THE TEXT THE TEXT"; echo wordwrap($text,8,"<br />\n"); Quote Link to comment https://forums.phpfreaks.com/topic/128956-how-do-i-add-line-breaks/#findComment-668566 Share on other sites More sharing options...
chronister Posted October 18, 2008 Share Posted October 18, 2008 To get an actual line break you can use the <br /> tag. e.g. <?php $line2break = 'This is a line. I want a break right here<br /> This is a new line'; echo $line2break; ?> Gives you This is a line. I want a break right here This is a new line. Nate Quote Link to comment https://forums.phpfreaks.com/topic/128956-how-do-i-add-line-breaks/#findComment-668624 Share on other sites More sharing options...
Maq Posted October 18, 2008 Share Posted October 18, 2008 No way that's how it's done? Wow... This is what I am working with http://www.joaomak.net/util/dtr/. I want to be able to do word warp in images. So would it work Zenag? $text="THE TEXT THE TEXT THE TEXT THE TEXT THE TEXT THE TEXT THE TEXT THE TEXT"; echo wordwrap($text,8," \n"); It should work, I don't see why not. Test it.... Quote Link to comment https://forums.phpfreaks.com/topic/128956-how-do-i-add-line-breaks/#findComment-668626 Share on other sites More sharing options...
CroNiX Posted October 18, 2008 Share Posted October 18, 2008 It will work for that specific example...generally not the best way to go. Quote Link to comment https://forums.phpfreaks.com/topic/128956-how-do-i-add-line-breaks/#findComment-668627 Share on other sites More sharing options...
Maq Posted October 18, 2008 Share Posted October 18, 2008 It will work for that specific example...generally not the best way to go. I agree. Different designs/circumstances call for different solutions. If this works for you then go ahead, but if you would explain your situation then maybe we could give you a better solution Quote Link to comment https://forums.phpfreaks.com/topic/128956-how-do-i-add-line-breaks/#findComment-668628 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.