first characters of a string

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
andresbezem
Forum Newbie
Posts: 2
Joined: Wed May 11, 2005 10:18 pm

first characters of a string

Post by andresbezem »

What function should I use if I want to print the first 50 characters from a string?

I know that substr works the other way around, it takes out of the string the first X numbers of characters, but I can not find the function that lets me KEEP them.

Thanks to all
SBro
Forum Commoner
Posts: 98
Joined: Tue Sep 30, 2003 10:06 pm

Post by SBro »

substr() works the way you want it to eg.

Code: Select all

echo substr('abcdef', 0, 3); // will print 'abc'
Thus all you need to do is:

Code: Select all

echo substr($string, 0, 50);
Post Reply