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.
The below line of code echo true if php word exist in string.
Answer 2
We can also use preg_match() to determine that
Example
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'; }
ORif (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';
}
Comments
Post a Comment