MainStWebGuy Posted March 25, 2009 Share Posted March 25, 2009 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. Link to comment https://forums.phpfreaks.com/topic/151123-stristr-matching-values-to-a-txt-document-using-fgets/ Share on other sites More sharing options...
dubc07 Posted March 25, 2009 Share Posted March 25, 2009 By looking at your script the only means of display is to echo $fileHandle i see no way of putting the listed lines of city's into a variable. Link to comment https://forums.phpfreaks.com/topic/151123-stristr-matching-values-to-a-txt-document-using-fgets/#findComment-793888 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.