PHP substr() Function

PHP strtr() Function
PHP substr_compare() Function

what is the syntax of the SUBSTR() function in php?

substr(string,start,length)
ParameterDescription
stringRequired. Specifies the string to return a part of
startRequired. Specifies where to start in the stringA positive number – Start at a specified position in the stringA negative number – Start at a specified position from the end of the string0 – Start at the first character in string
lengthOptional. Specifies the length of the returned string. Default is to the end of the string.A positive number – The length to be returned from the start parameterNegative number – The length to be returned from the end of the stringIf the length parameter is 0, NULL, or FALSE – it return an empty string
PHP SUBSTR() method

examples of the SUBSTR() function

Example 1. In this example, we return “world” from the string.

<?php
echo substr("Hello world",6);
?>

Example 1. In this example, we use the start parameter with different positive and negative numbers.

<?php
echo substr("Hello world",10)."<br>";
echo substr("Hello world",1)."<br>";
echo substr("Hello world",3)."<br>";
echo substr("Hello world",7)."<br>";

echo substr("Hello world",-1)."<br>";
echo substr("Hello world",-10)."<br>";
echo substr("Hello world",-8)."<br>";
echo substr("Hello world",-4)."<br>";
?>
PHP strtr() Function
PHP substr_compare() Function
en English
X
Scroll to Top