loops - for each .txt file line create a new link with .txt file line data in php -


i create .php file read .txt file , each line in text file take data , create new link data.

example:

list.txt

r2389 y3323 u3330 d2723 

reader.php

<?php     $myfile = "list.txt";     $lines = file($myfile); ?> <a href="http://website.com/<?php echo $lines[0];?>">link 1</a> <a href="http://website.com/<?php echo $lines[1];?>">link 2</a> <a href="http://website.com/<?php echo $lines[2];?>">link 3</a> <a href="http://website.com/<?php echo $lines[3];?>">link 4</a> 

reader.php output

<a href="http://website.com/r2389">link 1</a> <a href="http://website.com/y3323">link 2</a> <a href="http://website.com/u3330">link 3</a> <a href="http://website.com/d2723">link 4</a> 



this information , echo link.
means need create right amount of links work properly, in end want able edit list.txt , have php automatically create a

<a href="<?php echo $lines[*];?>">link *</a> 

depending on amount of lines in list.txt. label

<a>link *</a> 

depending on line number.

thanks in advance.

just loop through array.

<?php     $myfile = "list.txt";     $lines = file($myfile);      $linenumber = 1;     foreach($lines $line)     {     ?>     <a href="http://website.com/<?php echo $line;?>">link <?php echo $linenumber?></a>     <?     $linenumber++;     }     ?> 

Comments