Page 1 of 1

first characters of a string

Posted: Wed May 11, 2005 10:21 pm
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

Posted: Wed May 11, 2005 10:38 pm
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);