Skip to main content

Posts

Showing posts from April, 2017

PHP check a string contains specific value or string

How to check if a string having specific characters or string In PHP we can check with strpos() . strpos() is the simplest way to get string having search texts or not. Examples :- For examle here is a php string and we want to know that it contains "php" word or not. $a = 'Hello string do u have php word?'; The below line of code echo true if php word exist in string. if (strpos($a, 'php') !== false) { echo 'true'; } OR if (strpos($string, $word) === FALSE) { ... not found ... } Answer 2 We can also use preg_match() to determine that Example if (preg_match('/php/',$a)) {   echo 'true'; }