Page 1 of 2
Case insensitivity
Posted: Fri May 05, 2006 2:01 pm
by ozzy
I have just put together a search script using glob...
Code: Select all
<?php
$term = trim($_POST['query']);
$files = glob($dir."modules/Exploits/files/*".$term."*");
foreach( $files as $key => $value ){
echo $value."<br>";
}
?>
But the problem is if i am seaching for a file called 'Test' and i type in 'test', it wont dispaly it, but if i type in 'Test' it will. I was thinking about using eregi, but i dont know how i would intigrate it into my script, could anyone help?
Posted: Fri May 05, 2006 3:55 pm
by s.dot
strcasecmp(),
strtolower(), and
strtoupper() come to mind.
or
preg_match() with the i pattern modifier.
Posted: Fri May 05, 2006 4:07 pm
by ozzy
Do you know how i would edit:
Code: Select all
<?php
$var1 = "Hello";
$var2 = "hello";
if (strcasecmp($var1, $var2) == 0) {
echo '$var1 is equal to $var2 in a case-insensitive string comparison';
}
?>
so that it would do the whole alphabet, rather than going through them separately?
Posted: Fri May 05, 2006 4:21 pm
by someberry
Or the good 'ol ===?
Posted: Fri May 05, 2006 4:25 pm
by ozzy
someberry wrote:Or the good 'ol ===?
Pardon?
Posted: Sat May 06, 2006 2:18 am
by someberry
ozzy wrote:someberry wrote:Or the good 'ol ===?
Pardon?
Code: Select all
$var = 'Hello';
if($var === 'hello')
{
echo('if-statement #1 was executed.');
}
else if($var === 'Hello')
{
echo('if-statement #2 was executed.');
}
Output:
Posted: Sat May 06, 2006 4:03 am
by ozzy
Ah cool, is there any way of using it to do the whole alphabet like a-z equal to A-Z rather than having to go through them separately?
Posted: Sat May 06, 2006 6:24 am
by feyd
ozzy wrote:Ah cool, is there any way of using it to do the whole alphabet like a-z equal to A-Z rather than having to go through them separately?
Can you post an example of what you mean? I have no idea what you're talking about.
Posted: Sat May 06, 2006 9:20 am
by ozzy
I know this wont be syntaxly correct, but it is justa example im using to try to get people to understand what i mean...
Instead of doing something like:
Code: Select all
$var1 = "a";
$var2 = "A";
$var3 = "b";
$var4 = "B";
$var5 = "c";
$var6 = "C";
ect.
Is there any way in doing it in one var, (not syntaxly correct, example):
Hope i have made it more clear.
Posted: Sat May 06, 2006 9:22 am
by feyd
I have no idea what you're trying to do with that.
Posted: Sat May 06, 2006 10:04 am
by s.dot
Code: Select all
$str = 'Test';
$str2 = 'test';
if(preg_match("#test#i",$str)){
echo 'string matched';
}
if(preg_match("#test#i",$str)){
echo 'string 2 matched';
}
Posted: Sat May 06, 2006 10:06 am
by s.dot
or
Code: Select all
if(preg_match("[a-z]+#i",$your_data)){
echo 'I will match any letter of the alphabet, capitalized or not.';
}
Posted: Sat May 06, 2006 12:37 pm
by ozzy
Thanks scottayy, that's what i ment.

But when added with my script:
Code: Select all
<?php
$term = trim($_POST['query']);
if(preg_match("[a-z]+#i",$term)){
}
$files = glob($dir."./*".$term."*");
foreach( $files as $key => $value ){
echo $value."\n";
}
?>
I get the following error:
Code: Select all
Warning: preg_match() [function.preg-match]: Unknown modifier '+' in /host/localhost/htdocs/test.php on line 5
Posted: Sat May 06, 2006 2:32 pm
by s.dot
sorry, I made a typo
should be
Posted: Sat May 06, 2006 3:25 pm
by ozzy
Ah, cool. Now comming back to the whole case insensitivity how would i peace that together with
Code: Select all
<form action="" method="POST"><input size="25" type="text" name="query" value=""> <input type="submit" value="Search"></form>
<?php
$term = trim($_POST['query']);
}
$files = glob($dir."./*".$term."*");
foreach( $files as $key => $value ){
echo $value."\n";
}
?>
I have tryed
Code: Select all
<form action="" method="POST"><input size="25" type="text" name="query" value=""> <input type="submit" value="Search"></form>
<?php
$term = trim($_POST['query']);
}
if(preg_match("#[a-z]+#i",$term))
$files = glob($dir."./*".$term."*");
foreach( $files as $key => $value ){
echo $value."\n";
}
?>
and
Code: Select all
<form action="" method="POST"><input size="25" type="text" name="query" value=""> <input type="submit" value="Search"></form>
<?php
$term = trim($_POST['query']);
}
if(preg_match("#[a-z]+#i",$term))
$files = glob($dir."./*".$term."*");
foreach( $files as $key => $value ){
if(preg_match("#[a-z]+#i",$value))
echo $value."\n";
}
?>
But they didnt seem to work. :\