How to check word exist in string or not in PHP?

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Today now here I want to share on this posts because when i was first time working in my laravel application i need to find a word from string, Here I mean need to check a string contains on word or not but i was try to do, at last i was found two way we can check easily. At First one is by using preg_match and other one is by using strpos() of php predefine. If you have any question about how to php regular expression match word then i hope you can do this on that way:

Example 1:

$str = "Hi, I am from CosingsPoint.com";
if (strpos($str, "from") !== false) {
    print_r("Yes, exists");
}

Example 2:

$str = "Hi, I am from CosingsPoint.com";
$result = preg_match("from", $str);

if($result == 1){
 print_r("Yes, exists");
}

Read Also : How to convert Object into Array in PHP?

Thanks for read. I hope it help you. For more you can follow us on facebook.

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →