Substr () PHP Function
February 13th, 2010 — adminThe Substr () PHP Function is used to return part of a string. It is written as substr (string, start, optional length);.The string is whatever string you want to return a portion of. The start is how many characters in to skip before starting. Setting this to 3 would skip the first three and start returning at the forth character. Setting this to a negative number will start counting backwards from the end of the string.
Length is an optional parameter. If you set this to a positive number, it will return that number of characters. If you set this to a negative number it will count that many numbers from the end of the string and return whatever is left in the middle.
Length is an optional parameter. If you set this to a positive number, it will return that number of characters. If you set this to a negative number it will count that many numbers from the end of the string and return whatever is left in the middle.
See how this works :
<?php
// this will return bcdefghijk
echo substr(‘abcdefghijk’, 1);
echo “<br>”;// this will return defghijk
echo substr(‘abcdefghijk’, 3);
echo “<br>”;// this will return abc
echo substr(‘abcdefghijk’, 0, 3);
echo “<br>”;// this will return ijk
echo substr(‘abcdefghijk’, -3);
echo “<br>”;// this will return bcdefghij
echo substr(‘abcdefghijk’, 1, -1);
echo “<br>”;// this will return cdefgh
echo substr(‘abcdefghijk’, 2, -3);
echo “<br>”;
?>
If you would like this article please donate, this will keep us motivated!
Add to your favourite







































March 22nd, 2010 at 12:19 pm
[...] Author: Sam Burdge … The email_protect php function can be called on any text string like so: …Substr () PHP Function http://www.shashionline.inTutorial,Indian Institutions,IT Companies,Projects,Interview Question,E-Books,Free [...]
May 9th, 2010 at 4:48 pm
It’s posts like this that keep me coming back and checking this site regularly, thanks for the info!
June 8th, 2010 at 1:23 am
Substr PHP Function PHP PHP Function Function www shashionline inIt posts like this that keep me coming back and checking this site regularly, thanks for the info!6/8/2010
June 16th, 2010 at 11:19 am
My cousin recommended this blog and she was totally right keep up the fantastic work!