rileypool Posted November 27, 2007 Share Posted November 27, 2007 Hey all, I'm new to this forum and it looks like I'll be spending a lot of time here soon as I'm just now actually starting to LEARN php instead of hacking around various scripts I've used in the past. My question lies with the code below. I'm reading a .txt file that is full of nothing but urls on every line. I want to read every line from that text file and display that image using HTML. How would this be done? This is what I have so far but the url I'm reading from the text file isn't being inserted into the <img> tag. <?php $file = fopen("http://www.example.com/urls.txt", "r") or exit("Unable to open file!"); //Output a line of the file until the end is reached while(!feof($file)) { $urltxt = fgets($file); echo fgets($file). "<img src=" . $urltxt . "><br />"; } fclose($file); ?> Link to comment https://forums.phpfreaks.com/topic/79056-simple-fopen-question/ Share on other sites More sharing options...
rileypool Posted November 27, 2007 Author Share Posted November 27, 2007 I'm sure this is what this forum likes to see. A n00bie who is also troubleshooting his answer while awaiting for some help. I got it fixed now and I'm posting the correct code in my original post. Link to comment https://forums.phpfreaks.com/topic/79056-simple-fopen-question/#findComment-400088 Share on other sites More sharing options...
schme16 Posted November 27, 2007 Share Posted November 27, 2007 Why not try this: <?php $filename = 'file_location/file_name.txt'; $contents = file_get_contents($filename); $contents = explode($contents, ' ' ); foreach($contents as $url) { print $url; echo'<br />'; } ?> I haven't tested it... but it looks right to me... Link to comment https://forums.phpfreaks.com/topic/79056-simple-fopen-question/#findComment-400126 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.