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 :: Number of week days between two dates in php 
Php :: php artisan tinker encription cmd 
Php :: php json data to array 
Php :: laravel except method 
Php :: php assign if not null 
Php :: php json_decode not working 
Php :: add two numbers in php 
Php :: laravel route optional parameter 
Php :: Carbon Add Years To Date In Laravel 
Php :: how to execute php function on button click 
Php :: php file_put_contents inode problem 
Php :: laravel storage link without command line 
Php :: mysqli exception handling 
Php :: Composer detected issues 
Php :: Laravel migrations custom foreign key 
Php :: Add Text Before the Product Title 
Php :: parse json nested array form url in php 
Php :: laravel request has 
Php :: how to include javascript in php 
Php :: php != operator 
Php :: symfony connect rabbitMQ 
Php :: update query laravel 
Php :: php isset form submit 
Php :: dependable validation in laravel 
Php :: eloquent first 
Php :: call to a member function get_results() on null 
Php :: preg_replace allow spaces 
Php :: php query to hide duplicate records 
Php :: Displaying Custom Navigation Menus in WordPress Themes 
Php :: extract text before last space php 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =