Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php check if string contains words from array

$string = "This dude is a mean mothertrucker";
$badwords = array('truck', 'shot', 'ass');
$banstring = ($string != str_ireplace($badwords,"XX",$string))? true: false;
if ($banstring) {
   echo 'Bad words found';
} else {
    echo 'No bad words in the string';
}
Comment

php check if some string contains from array

$string = 'my domain name is website3.com';
foreach ($owned_urls as $url) {
    //if (strstr($string, $url)) { // mine version
    if (strpos($string, $url) !== FALSE) { // Yoshi version
        echo "Match found"; 
        return true;
    }
}
echo "Not found!";
return false;
Comment

php check if some string contains from array

$array = ["they has mystring in it", "some", "other", "elements"];
if (stripos(json_encode($array),'mystring') !== false) {
echo "found mystring";
}
Comment

php find if string contains words from list index

$owned_urls = array('website1.com', 'website2.com', 'website3.com');

//this example should return FOUND
$string = 'my domain name is website3.com';
if (array_in_string($string, $owned_urls)) {
    echo "first: Match found<br>"; 
}
else {
    echo "first: Match not found<br>";
}

//this example should return NOT FOUND
$string = 'my domain name is website4.com';
if (array_in_string($string, $owned_urls)) {
    echo "second: Match found<br>"; 
}
else {
    echo "second: Match not found<br>";
}
Comment

PREVIOUS NEXT
Code Example
Php :: What does PEAR stands for? 
Php :: print only some characters of a string in php 
Php :: wp tax_query in 
Php :: maintaining serial number in laravel pagination table 
Php :: php textarea replace newline with br 
Php :: laravel select only some columns relationship 
Php :: eloquent update row response 
Php :: comment in php 
Php :: php artisan down allow ip 
Php :: composer update php mbstring.so missing 
Php :: php shell_exec with root 
Php :: php best debugging functions 
Php :: get woocommerce product category link by id 
Php :: php imagick xampp windows 
Php :: php check if class exists 
Php :: laravel validation unique email except self 
Php :: php convert string to chars 
Php :: how validate the value of object in arraye in laravel 
Php :: wordpress get local date 
Php :: Merge Two Array ( Laravel ) 
Php :: send OTP php 
Php :: mcrypt php extension required 
Php :: install php 5.6 mac 
Php :: print asociative array php 
Php :: sum of multidimensional array in php 
Php :: number format without comma php 
Php :: how to get match date and month in php 
Php :: how to serve the port in php 
Php :: how to do a submit button in php without reloading the page 
Php :: php switch case array 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =