Search engine

Question by :
PHP Reading files script problem?

I am having trouble with my PHP classes and was hoping someone could help me complete this script because it has me beat. I realize that this is suppose to be very basic, I am just having a very difficult time with it.

So basically, I need to

Read the file line by line, and use the explode and list functions to extract the category, rating, URL, and description. Use that information to write out a web page that contains each link and description, such as the following:

Maps
hopstop.com – A good way to find your way from here to there in major cities.

News
chicagotribune.com – The on the web version of the Chicago Tribune newspaper

Maps
mapquest.com – Find an address on a map or get directions from one place to another. ‘

At the moment I have this, ( I know that the explode command has to be in the wrong place I just dont know what I am missing.

My text file I am reading is named results.txt and everything that depends on it is in the correct place.
An example of the text it has is.

Random|3|google.com|Search Engine
Humor|9|whiteninjacomics.com|The adventures of White Ninja.
Games|5|wowhead.com|For all your WoW needs
Science|9|www.blender3d.com|A free open-source 3d graphics program!
News|8|digg.com|tech news
Random|1|myspace.com|Laugh at em.

The first field being the category the second being the rating and the third is the actual URL.

$ filename = "../write/results.txt";

print "

Results.txt

“;

if(($ fp=fopen($ filename,”r”))===false)
print(“Couldnt open the file”);
else
{
$ line = fgets($ fp);
while (!feof($ fp))
{

print htmlentities($ line).’
‘;

$ line = fgets($ fp);
}
fclose($ fp);

}

print “


“;

$ line=”games|9|http://www.gamefaqs.com”;
$ a = explode(“|”,$ line);
list($ Category,$ Rating,$ URL) = $ a;
print(“$ Category,$ Rating,$ URL
“);

?>
That really Helped thanks!

Do you know how I would be able to split the data up into their categories and then have them listed by rank ex:

Also how would I make the URLs actual links?

Maps
1 mapquest.com – Find an address on a map or get directions from one place to another.
2 hopstop.com – A good way to find your way from here to there in major cities.

News
5 chicagotribune.com – The on the web version of the Chicago Tribune newspaper

etc.


——————————————

Answer by _anonymous_
first, you might want to take this out:

print htmlentities($ line).’
‘;

this simply prints the original contents of the file. (or keep it if you want)

also, put this:

$ a = explode(“|”,$ line);
list($ Category,$ Rating,$ URL) = $ a;
print(“$ Category,$ Rating,$ URL
“);

right after the while() { line, so this step simply keeps looping for each line

finally, take this out:

$ line=”games|9|http://www.gamefaqs.com…

this states to always make the line equal to the description of gamefaqs.com

——————————————
Know better? Leave your own answer in the comments!