Jump to content

Simple fopen() question


rileypool

Recommended Posts

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

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

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.