How to make strpos case insensitive

You’re looking for stripos() If that isn’t available to you, then just call strtolower() on both strings first. EDIT: stripos() won’t work if you want to find a substring with diacritical sign. For example: stripos(“Leży Jerzy na wieży i nie wierzy, że na wieży leży dużo JEŻY”,”jeży”); returns false, but it should return int(68).

PHP check if file contains a string

Much simpler: <?php if( strpos(file_get_contents(“./uuids.txt”),$_GET[‘id’]) !== false) { // do stuff } ?> In response to comments on memory usage: <?php if( exec(‘grep ‘.escapeshellarg($_GET[‘id’]).’ ./uuids.txt’)) { // do stuff } ?>

Simple PHP strpos function not working, why?

When in doubt, read the docs: [strpos] Returns the numeric position of the first occurrence of needle in the haystack string. So you want to try something more like: // … if (strpos($link, $unacceptable) !== false) { Because otherwise strpos is returning a number, and you’re looking for a boolean true.

Using an array as needles in strpos

@Dave an updated snippet from http://www.php.net/manual/en/function.strpos.php#107351 function strposa($haystack, $needles=array(), $offset=0) { $chr = array(); foreach($needles as $needle) { $res = strpos($haystack, $needle, $offset); if ($res !== false) $chr[$needle] = $res; } if(empty($chr)) return false; return min($chr); } How to use: $string = ‘Whis string contains word “cheese” and “tea”.’; $array = array(‘burger’, ‘melon’, ‘cheese’, ‘milk’); … Read more