Follow us on Twitter!
Become the change you seek in the world. - Gandhi
Sunday, April 20, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 25
Guests Online: 23
Members Online: 2

Registered Members: 82843
Newest Member: hx47
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

PHP script


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 04-10-06 07:39
Im trying to write a script that searches a text file to see if a word is in it.
:::Things to note:::

I've only started learning php today
$search is the string that the user enters into the text box.
Textfile format is
line 1
line 2
line 3
(If that makes a difference.

:::Here is my code:::


<?php

$wordlist="words2.txt";
$list = file ($wordlist);
foreach ($list as $word) {
if ($search == $word) {
echo "Found!";
}
}

?>

It doesn't search it line by line, checking each line at a time (Which is what i want). It only compares $search with the last word in the text file.

Can anyone help me so it will search for any word in the file, not just the last one?

Any help would be appreciated extremely Smile
Author

RE: PHP script


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 04-10-06 09:14
Well personally I would use a regular expression (regex) and then I could do preg_match_all() but thats just me


Author

RE: PHP script


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 04-10-06 20:00
Haven't done anything like this, just started PHp a while ago but you could use the "explode" command to make the file an array made up of individual words and check them
Author

RE: PHP script


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 04-10-06 20:38
I have to agree with mozzer with the regex thingy. Regexes are slow in some cases but when you're handling bigger files you won't regret using them.

About the explode function, if you have a 3000 word text than the zend engine would need to preserve memory for an array of 3000 strings. Which isn't this performant Wink


Author

RE: PHP script


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 04-10-06 20:43
Well the point is when your reading a file line by line there is always the caracter "\r\n" or "\n" at the end. So if you want to compare it with a word add $word = str_replace(Array("\r","\n"),"",$word); and this should be ok.




Edited by on 04-10-06 20:44
Author

RE: PHP script


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 04-10-06 21:11
<?php

$wordlist="words2.txt";
$list = file ($wordlist);
foreach ($list as $word) {
if ($search == $word) {
echo "Found!";
}
}

?>


so if you wanted to seperate every thing by spaces, then that would seperate the words. soo you could change it to
Code

<?php

$wordlist="words2.txt";
$list = file ($wordlist);
foreach ($list as $search {
list($search)=split(" ", $search);
if($search==$word){
echo "Found!";
}
}

?>







Author

RE: PHP script


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 05-10-06 17:08
Thanks everyone for your help. I didn't realize it added "/r/n" to every word, just had to take that off and it fixed it (Thanks Arto_8000).

Just in case you were wondering a was trying to make an md5 dictionary cracker. I know most wouldn't be interested, but i thought id post the code. It probably could be tidier, but hey.


Code


<?php

$wordlist="words.txt";
$list = file ($wordlist);
$search = strtolower($search);
$search .= "";
foreach ($list as $word) {

$word = substr_replace($word,"",-1);

if ($search == md5(substr_replace($word,"",-1))) {
   echo "<i>$search</i>", "=", " ","<b>$word</b>", " - Successfully cracked!";
$nocrack = 1;
}
}

if ($nocrack ==0) {
   echo "Crack unsuccessful!";
   }

?>





My very first php script, yay!


Edited by on 05-10-06 17:14
Author

RE: PHP script


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 05-10-06 17:19
Well actually there are a few PHP scripts for MD5 dictionary crackers in the code-bank so you could've just gotten ideas from them
Author

RE: PHP script


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 06-10-06 05:46
Happysmileman wrote:
Well actually there are a few PHP scripts for MD5 dictionary crackers in the code-bank so you could've just gotten ideas from them


Thanks for your input, but I didn't copy any md5 cracker scripts - bit of jealous maybe?
Author

RE: PHP script

richohealey
Member



Posts: 1022
Location: #!/usr/local/bin/python
Joined: 01.05.06
Rank:
Monster
Posted on 06-10-06 05:49
i think what he was saying is that you could have looked at the code back, and seen the other scripts, and used them to find your bug.


bitchohealey at hotmail dot com skype:richohealey www.psych0tik.net
Author

RE: PHP script

richohealey
Member



Posts: 1022
Location: #!/usr/local/bin/python
Joined: 01.05.06
Rank:
Monster
Posted on 06-10-06 05:50
i think what he was saying is that you could have looked at the code back, and seen the other scripts, and used them to find your bug.


bitchohealey at hotmail dot com skype:richohealey www.psych0tik.net