In this tutorial, we are going to see how to extract a substring from a string in PHP. substr() function in PHP can be used to get the substring(part of a string). This function takes the start index and length parameters to return the substring from a string.
<?php $str = "Welcom To StackHowTo!"; echo substr($str, 0, 6); ?>
Here, we start from the end of the string.
<?php $str = "Welcom To StackHowTo!"; echo substr($str, -13, 12); ?>
StackHowToMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More