Sub string -How to use it

<?php
$rest = substr(”ramanean”, -1);    // returns “n”
$rest = substr(”ramanean”, -2);    // returns “an”
$rest = substr(”ramanean”, -3, 1); // returns “n”
?>
Another example of Sub string

<?php
$rest = substr(”ramanean”, 0, -1);  // returns “ramanea”
$rest = substr(”ramanean”, 2, -1);  // returns “manea”

?>

Substrings are very useful and can be used to strip out certain characters from a word.For example:http:// from a website’s address etc., and also there is another function called sub string replace is there which is related to sub string.

Substr_replace() is a function which will help you to replace sub string characters in a word.For example http://rediff.com can be replaced by www.rediff.com etc.,

Leave a comment

Your comment