Horje

PHP Match Specific Word

Here is a function that can perform this operation without using regular expressions which could be slower. Instead of passing a single string for the task, pass an array like
index.php
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';
}

?>

Output should be:

PHP Match Specific Word




Type:
php
Category:
Web Tutorial
Sub Category:
PHP String Tutorial
Uploaded by:
Admin