How to Access Substring in PHP

How to Expose and Route to a Resource?
How to Expose and Route to a Resource?

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.

How to Access Substring in PHP

Solution – How to Access Substring in PHP

<?php

$email = info@159.89.173.208;
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

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *