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); ?> Quote Link to comment 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. Quote Link to comment 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... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.