I have made a php script that searches a whole directory with text files in it, everything works fine, except that it is case sensitive. How would i search without it being case sensitive? Here's the code i have so far:
<?php
$query = $_POST['search'];
if ($handle = opendir('posts')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
echo "<p>$entry ";
$file = file_get_contents('posts/'.$entry, FILE_USE_INCLUDE_PATH);
$check_str = strpos($file,$query);
if ($check_str == 0) {
print "not found</p>";
} else {
print "found</p>";
}
}
}
closedir($handle);
}
?>
Note: The stripos() function is case-insensitive.
The strcasecmp() function compares two strings. Tip: The strcasecmp() function is binary-safe and case-insensitive. Tip: This function is similar to the strncasecmp() function, with the difference that you can specify the number of characters from each string to be used in the comparison with strncasecmp().
In PHP, class names as well as function/method names are case-insensitive, but it is considered good practice to them functions as they appear in their declaration.
No, Keywords are not case-sensitive.
Yeah, stripos()
is what you're looking for. Here's the manual page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With