Use of substr() PHP function
PHP is having a very cool function to substract the length of a string. Use of substr() PHP function is very easy and simple. See the below example to know how it works.
PHP Code:
The output of the above code will be:
Code:
PHP Code:
The output of the above code will be:
Code:
Code:
PHP is having a very cool function to substract the length of a string. Use of substr() PHP function is very easy and simple. See the below example to know how it works.
PHP Code:
The above code will substract the first five letters from the string.<?php
$QUERY = "Substract starting five letters from me.";$QUERY = substr($QUERY, '0', '5');
echo $QUERY;?>
The output of the above code will be:
Code:
SubstSimilarly we can substract a part of any string using this function. Just specify a start point and an end point. look at the below example for better explaination.
PHP Code:
The above code will substract all letters coming after 10 and upto 15th character from the string.<?php
$QUERY = "Substract any five letters from me." $QUERY = substr($QUERY, '10', '15');
echo $QUERY;?>
The output of the above code will be:
Code:
any five letter
Similarly we can use it in this way,Code:
Try it yourself and you will enjoy learning PHP ..<?php
$rest = substr("abcdef", -1); // returns "f"
$rest = substr("abcdef", -2); // returns "ef"
$rest = substr("abcdef", -3, 1); // returns "d"
?>
No comments:
Post a Comment