PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
ozzy
Forum Commoner
Posts: 74 Joined: Tue Apr 11, 2006 4:45 pm
Post
by ozzy » Fri May 05, 2006 2:01 pm
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?
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Fri May 05, 2006 3:55 pm
strcasecmp() ,
strtolower() , and
strtoupper() come to mind.
or
preg_match() with the i pattern modifier.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
ozzy
Forum Commoner
Posts: 74 Joined: Tue Apr 11, 2006 4:45 pm
Post
by ozzy » Fri May 05, 2006 4:07 pm
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?
someberry
Forum Contributor
Posts: 172 Joined: Mon Apr 11, 2005 5:16 am
Post
by someberry » Fri May 05, 2006 4:21 pm
Or the good 'ol ===?
ozzy
Forum Commoner
Posts: 74 Joined: Tue Apr 11, 2006 4:45 pm
Post
by ozzy » Fri May 05, 2006 4:25 pm
someberry wrote: Or the good 'ol ===?
Pardon?
someberry
Forum Contributor
Posts: 172 Joined: Mon Apr 11, 2005 5:16 am
Post
by someberry » Sat May 06, 2006 2:18 am
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:
ozzy
Forum Commoner
Posts: 74 Joined: Tue Apr 11, 2006 4:45 pm
Post
by ozzy » Sat May 06, 2006 4:03 am
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?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat May 06, 2006 6:24 am
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.
ozzy
Forum Commoner
Posts: 74 Joined: Tue Apr 11, 2006 4:45 pm
Post
by ozzy » Sat May 06, 2006 9:20 am
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.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat May 06, 2006 9:22 am
I have no idea what you're trying to do with that.
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Sat May 06, 2006 10:04 am
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';
}
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Sat May 06, 2006 10:06 am
or
Code: Select all
if(preg_match("[a-z]+#i",$your_data)){
echo 'I will match any letter of the alphabet, capitalized or not.';
}
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
ozzy
Forum Commoner
Posts: 74 Joined: Tue Apr 11, 2006 4:45 pm
Post
by ozzy » Sat May 06, 2006 12:37 pm
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
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Sat May 06, 2006 2:32 pm
sorry, I made a typo
should be
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
ozzy
Forum Commoner
Posts: 74 Joined: Tue Apr 11, 2006 4:45 pm
Post
by ozzy » Sat May 06, 2006 3:25 pm
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. :\