PHP in HindiProgramming Language

How to Access Substring in PHP

Problem:- How to Access Substring in PHP

You want to know if a string contains a particular substring how we can access that. For example we get a email id and we want to check @ in that email so how can we.

Solution – How to Access Substring in PHP

<?php

$email = [email protected];
if(strpos($email, @) === false){
    print 'this is not a vaild email address';
}

?>

How It Works

The return value from strpos() function the first parameter is haystack and 2nd parameter is needle that we want to check in out string(haystack). if no match found then we compare it with false that mean our condition is true and we will get this is not a valid email address output otherwise no output

Another Interesting Article

Related Articles

Leave a Reply

Your email address will not be published.

Back to top button
Close