Jump to content

How can i search in a txt file?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
lil-fino

lil-fino

    Newbie

  • Members
  • PipPip
  • 15 posts
Its possible to search through a txt file?
I made a php script that open a txt file and writes on it but now i want to be able to search through the file and find whats it on it.
The txt file looks kind of like this


.........

ctl00$ctl00$cpMain$cpMain$Box$firs_name=THEIR_NAME

ctl00$ctl00$cpMain$cpMain$Box$last_name=THEIR_LAST_NAME

.....


What i want to do its that when the user search for their first name it will show them their last name. Its just an example.

Sorry for my bad english.

#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
1. Read the file into a buffer either using fopen or filegetcontents
2. Search through the buffer

#3
lil-fino

lil-fino

    Newbie

  • Members
  • PipPip
  • 15 posts
can you please give an example?

thank you

#4
Guest_Jaan_*

Guest_Jaan_*
  • Guests
<?php

$file = "text.txt";
$open = fopen($file, "r");
$read = fread($open, filesize($file));

if(eregi("myWord", $read)) {
    
    echo "Found";
    
}else{
    
    echo "Not found";
    
}

?>

maybe this helps you :)

#5
lil-fino

lil-fino

    Newbie

  • Members
  • PipPip
  • 15 posts
thanks man than code looks beatiful:w00t:

#6
Guest_Jaan_*

Guest_Jaan_*
  • Guests
You're welcome mate :)