Jump to content

stristr: matching values to a txt document using fgets()


MainStWebGuy

Recommended Posts

Hello again all and thank you to those who've been such a great help to me so far. I can't wait till i can start answering some of these questions hehe.

 

My latest project has me at a loss... again. I have the following code...

 


$search_query = "hair cut shop in anytown";

$fileHandle = fopen('cities.txt', "r"); // open the text document that contains 
                                                   //my list of city names
                                                  //and assign its content to a variable 
                                                 //($fileHandle)

$cityfound="";               //set cityfound to blank

while (!feof($fileHandle)) { 	//while we're NOT (!) at the end of the file  
                                              //(cities.txt)
	$city = fgets($fileHandle);	//create each line into a variable
	if(stristr($search_query,$city)){
		$cityfound=$city;
		break;
	}	
}	
echo $cityfound;
echo "<br />"."here";

 

... and when i call it in my browser it echo's out "here" but not the city name ($cityfound).

 

My txt file (cities.txt) is a simple list of city names that looks like this:

 

Anytown

Townville

Butt Friggin' Egypt

City Town

 

From my previous questions, i'm used to my issues being a newbie mistake so feel free to point and laugh haha :-)

 

Oh and excuse (and correct if ya see anything!) my comments... it's my way of keeping things straight =D

 

thanks!

J

 

Oh - i forgot to mention: the cities.txt is in the same folder as the php file.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.