August 17, 2024
PHP substr
If you want to get sub string from a string so you can easily do this through PHP's built in function substr. This function required three parameters first is the whole string, second parameter indicate index value from where you want to retrieve the sub string and third parameter indicate how many character you want to retrieve, this third parameter is optional if you do not pass third parameter then function consider you required all the characters from the given index (second parameter). The example of substr is mentioned below:
Code
<?php
$msgVariable = "Hello, welcome in php world";
$subMsg = substr($msgVariable,7);
echo $revMsg; // this will print message welcome in php world
$subString = substr($msgVariable, 7 , 7);
echo $subString; // this will pring welcome on the screen
?>