Hello, i have a text file that contain many urls each url in a line in which i want to import into php webpage and make each url hyperlinked, can anybody help me in doing that, does anybody know the php code to do such thing, thanks mohammed
Sure just use: $urls =file('path/to/urls.txt'); foreach ($urls as $url) { echo "<a href=\"$url\">$url</a><br>"; } PHP:
Hi mikecampbell; Can you please define [ $urls =file('path/to/urls.txt'); ] that what will be "path" and what is "to" ? Thanks
The string path/to/urls.txt is just an example. Replace it with the real path to your file full of URLs.
php array is the best method to use this file. just use the following code which will print each your url line and will convert it into hyperlink $urls =file('your_file_location/to/file_name.txt'); foreach ($urls as $url) { echo "<a href=\"$url\">$url</a><br>"; }
You can use this one too. This will eliminate unnecessary line break and elements. <?php $urls=explode("\n",trim(file_get_contents('path/to/urls.txt'))); foreach ($urls as $url) { echo "<a href=\"$url\">$url</a><br>"; } ?> Code (php):