![]() |
|
Example:
PHP
<?php
$data = "bangla";
if (strpos($data, 'bangla')!==false || strpos($data, 'english')!== false) {
echo "Found";
} else {
echo "Not Found";
}
?>
Example:
PHP
<?php
// function
function strposMultiple($haystack, $needle, $offset = 0) {
if(is_string($needle))
return strpos($haystack, $needle, $offset);
else {
$min = false;
foreach($needle as $n) {
$pos = strpos($haystack, $n, $offset);
if($min === false || $pos < $min) {
$min = $pos;
}
}
return $min;
}
}
// PHP Code for Result
$data = 'bad';
if (strposMultiple($data, ['bad', 'naughty']) !== false) {
echo 'Matched';
} else {
echo 'Not Matched';
}
?>
For this, you will need Regular Expressions and the preg_match function. Something like:
Example:
PHP
<?php
$data = 'bad';
if(preg_match('(bad|naughty)', $data) === 1)
{
echo 'Yes';
} else {
echo 'No';
}
?>
(preg_match return 1 if there is a match in the string, 0 otherwise).
Example:
PHP
<?php
$data = 'bad';
if (strpos($data, 'bad')!==false or strpos($data, 'naughty')!== false) {
echo "Found";
} else {
echo "Not Found";
}
?>
How to check if a string contain multiple specific words | PHP String Tutorial |
How to extract words from Sentence in PHP | PHP String Tutorial |
How to check if string is_numeric() Function in PHP | PHP String Tutorial |
How to get only text from HTML Source Code by PHP | PHP String Tutorial |
How to get first 3 words from a sentence by PHP | PHP String Tutorial |
How to work if empty value does not else | PHP String Tutorial |
How to remove first Five Line from a TXT File in PHP | PHP String Tutorial |
How to get Longest Word from a Sentence in PHP | PHP String Tutorial |
How to remove first character from string php | PHP String Tutorial |
How to count if Number is below than 10 sum | PHP String Tutorial |
How to get back page link | PHP String Tutorial |
How to get first 3 longest words from a sentence PHP | PHP String Tutorial |
How to count number of words from sentence in PHP | PHP String Tutorial |
How to remove all number from a string php | PHP String Tutorial |
If match some word in php | PHP String Tutorial |
PHP Match Specific Word | PHP String Tutorial |
If Match Some Word | PHP String Tutorial |
If Multiple Word Match | PHP String Tutorial |
Read Full: | PHP String Tutorial |
Category: | Web Tutorial |
Sub Category: | PHP String Tutorial |
Uploaded by: | Admin |
Views: | 102 |
Reffered: https://stackoverflow.com