only print 8 characters

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
swamyt
Forum Newbie
Posts: 5
Joined: Tue Oct 14, 2008 4:18 am

only print 8 characters

Post by swamyt »

Hello,

I want to print only 8 characters then after print three dots using string functions

So please help me

Thanks And Regards
swamy
User avatar
Kadanis
Forum Contributor
Posts: 180
Joined: Tue Jun 20, 2006 8:55 am
Location: Dorset, UK
Contact:

Re: only print 8 characters

Post by Kadanis »

Code: Select all

 
<?php
 
$originalString = 'Hello World!';
 
$newString = substr($originalString, 0, 8) . '&hellip;';
 
//output is Hello Wo...
echo $newString;
?>
 
Edit: fixed, thanks onion ;)
Last edited by Kadanis on Tue Oct 14, 2008 11:13 am, edited 1 time in total.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: only print 8 characters

Post by onion2k »

Instead of ... as dots you really ought to be using &hellip;
Post Reply