Ads

Friday, August 13, 2021

Extracting substrings using php's strstr()

 


You can extract the substring from the corner string using the strstz () function. Two strings are used as arguments for this function: the first string is where you want to find the substring, and the second string is where you want to find it. If this substring is found, the result of this function will be from there to the last part of the string. For example, we can separate the domain part from the below php code for email address:


<? php

$email = "info@google.com";

$domain = strstr ($email, '@');

echo $domain;

?>


Note that this function is case sensitive. This means that if you search for it, you will only find it in the sixth hand, not in the upper hand. Use strist = () function if you want to get a and A for case insensitive i.e. a. Its use is similar to the strstr () function.


If the second argument of the stzstr () function is not a string, it is converted to an integer and compared to an ordinal number of characters. For example, the value of small hand a is 97. So it will look for a in the following code:


<?php

$string = 'I love google'; 

echo stristr($string, 97); // 97 = lowercase a

?>


If you look at it in the browser, you will see google as the output.