String contains any items in an array (case insensitive)
is that what you wanted? i hope that code is compiling :)
$string = 'My nAmE is Tom.';
$array = array("name","tom");
if(0 < count(array_intersect(array_map('strtolower', explode(' ', $string)), $array)))
{
//do sth
}
How can I make Array.Contains case-insensitive on a string array?
array.Contains("str", StringComparer.OrdinalIgnoreCase);
Or depending on the specific circumstance, you might prefer:
array.Contains("str", StringComparer.CurrentCultureIgnoreCase);
array.Contains("str", StringComparer.InvariantCultureIgnoreCase);
Check if any word from a string is in an array (Case insensitive)
You can use array_uintersect, which takes a comparison function in which you can do case-insensitive comparison with strcasecmp:
$response = 'Ingredients: Whey, bEEf, EgG, NuTs';
$items = array_map('trim', array_slice(preg_split('/[:,]/', $response), 1));
$array = [ 'Beef', 'Nuts'];
$result = array_uintersect($array, $items, fn($a, $b) => strcasecmp($a, $b));
print_r($result);
javascript includes() case insensitive
You can create a RegExp from filterstrings
first
var filterstrings = ['firststring','secondstring','thridstring'];
var regex = new RegExp( filterstrings.join( "|" ), "i");
then test
if the passedinstring
is there
var isAvailable = regex.test( passedinstring );
Check if string contains an element from array ignoring case (JavaScript)
Change from
chk => chk.toLowerCase().includes(chk)
to
val => val.toLowerCase().includes(chk.toLowerCase())
or
const ar = ["[Text]", "[More]", "[AnotherText]", "[Stuff]", "[Yes]"];
const isContain = (arr, chk) =>
arr.some(
(val) =>
val.toLowerCase().includes(chk.toLowerCase()) ||
chk.toLowerCase().includes(val.toLowerCase())
);
console.log(isContain(ar, "tExt"))
Check whether string contains substring (NON CASE SENSITIVE)
If you want to know whether array contains required non case sensitive string some with toLowerCase may be good solution:
const findStr = (arr, str) => arr.some(e => e.toLowerCase().search(str.toLowerCase()) !== -1)
const arr = ['Hallo', 'I am listening', 'CaLling iT', 'haLLing']
console.log(findStr(arr, 'CaLlI'))console.log(findStr(arr, 'i AM Lis'))console.log(findStr(arr, 'Ca1'))
Check if a string exists in an array case insensitively
you can use
word.lowercaseString
to convert the string to all lowercase characters
Check if string contains a value in array
Try this.
$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;
Use stristr() or stripos() if you want to check case-insensitive.
Detect if string contains any element of a string array
In additional to answer of @Sh_Khan, if you want match some word from group:
let str:String = "house near the beach"
let wordGroups:[String] = ["beach","waterfront","with a water view","near ocean","close to water"]
let worlds = wordGroups.flatMap { $0.components(separatedBy: " ")}
let match = worlds.filter { str.range(of:$0) != nil }.count != 0
Related Topics
How to Iterate Over Non-English File Names in PHP
PHP Fatal Error: Call to Undefined Function MySQLi_Stmt_Get_Result()
Set Session Variable Using JavaScript in PHP
Custom Order Status Background Button Color in Woocommerce 3.3 Admin Order List
How to Send Email from Localhost Using PHP on Linux
Swift Httppost Data Not Inserting to MySQL Database
How to Bind Multiple Parameters to MySQLi Query
How to Get Int Instead String from Form
Get Numbers from String with PHP
Differencebetween the PHP Open Tags "<=" and "<Php"/"<"
Http Options Request on Azure Websites Fails Due to Cors
Strange Behaviour with Numbers That Have a Leading Zero
Sort Multi-Dimensional Array by Specific Key
Best Methods to Clean Up a Hacked Site with No Clean Version Available