Hello Developers,
In this demonstration, you will find the usage of substr()
in PHP.
The substr()
function requires three parameters. These are given below:
substr(string
$string
, int$offset
, ?int$length
=null
): string
Returns the portion of string
specified by the offset
and length
parameters. First, we have to open up a code editor and paste the below code to run the file to see the output. We can see two examples from the below code:
<?php
$name="John Doe";
//if length is negative it starts removing from the end
$result = substr($name,0,-3);
echo $result; echo '<br>';
//if length is positive it starts removing from the begining
$result = substr($name, 0, 6);
echo $result;
Output:
John
John r
I hope this might help you in the journey of development.
Read More: How to read multiple query stored procedure from mssql to Laravel project