twittoris Posted October 8, 2009 Share Posted October 8, 2009 I have a script which reads a .txt file formatted URL|Description it then loops the entries into a table. However, the URL is not a clickable link. How do I include an ahref in the loop? while (!feof($fp)) { $line = fgets($fp,1024); //use 2048 if very long lines $row++; list ($website, $description)= split ("\|", $line); $col[$row] = array($row, $website, $description, $adsense); Help?? Link to comment https://forums.phpfreaks.com/topic/176925-solved-passing-links-through-php-table/ Share on other sites More sharing options...
syed Posted October 8, 2009 Share Posted October 8, 2009 while (!feof($fp)) { $line = fgets($fp,1024); //use 2048 if very long lines $row++; list ($website, $description)= split ("\|", $line); echo "<a href=\"" . $website . "\">" . $website . "</a><br/>"; echo $description; } Link to comment https://forums.phpfreaks.com/topic/176925-solved-passing-links-through-php-table/#findComment-932861 Share on other sites More sharing options...
twittoris Posted October 8, 2009 Author Share Posted October 8, 2009 close.... while (!feof($fp)) { $line = fgets($fp,1024); //use 2048 if very long lines $row++; list ($website, $description)= split ("\|", $line); $website= "<a href=\"" . $website . "\">" . $website . "</a><br/>"; $col[$row] = array($row, $website, $description, $adsense); the webpage column is now a clickable hyperlink. However, the url is http://mysite.com/www.$website.com i.e. www.mysite.com/www.yahoo.com which does not go to the right webpage Link to comment https://forums.phpfreaks.com/topic/176925-solved-passing-links-through-php-table/#findComment-932990 Share on other sites More sharing options...
twittoris Posted October 8, 2009 Author Share Posted October 8, 2009 my last post wasnt entirely accurate, it works if http:// was entered in the text file. is there a check we could apply that would add an http or take an extra http away? Link to comment https://forums.phpfreaks.com/topic/176925-solved-passing-links-through-php-table/#findComment-932993 Share on other sites More sharing options...
Glenugie Posted October 8, 2009 Share Posted October 8, 2009 We could use the Substring function $String = "http://....."; $Http = substr($String, 0,7); if ($Http=="http://") { //code to be executed if the website starts with http:// } else { //code to be executed if it doesn't } Hope this helps Link to comment https://forums.phpfreaks.com/topic/176925-solved-passing-links-through-php-table/#findComment-932997 Share on other sites More sharing options...
twittoris Posted October 8, 2009 Author Share Posted October 8, 2009 yeah i see where you are going. I am new to php and am not sure how to apply it to my code above... Link to comment https://forums.phpfreaks.com/topic/176925-solved-passing-links-through-php-table/#findComment-933019 Share on other sites More sharing options...
Glenugie Posted October 8, 2009 Share Posted October 8, 2009 while (!feof($fp)) { $line = fgets($fp,1024); //use 2048 if very long lines $row++; list ($website, $description)= split ("\|", $line); $Http = substr($website, 0,7); if ($Http=="http://") { echo <a href=\"".$website. "\">" . $website . "</a><br/>"; } else { echo <a href=\"http://".$website. "\">" . $website . "</a><br/>"; } $col[$row] = array($row, $website, $description, $adsense); Might do the trick, I think ~Glenugie~ Link to comment https://forums.phpfreaks.com/topic/176925-solved-passing-links-through-php-table/#findComment-933024 Share on other sites More sharing options...
twittoris Posted October 8, 2009 Author Share Posted October 8, 2009 had to change it to the variable instead of echo but now it works perfectly. Link to comment https://forums.phpfreaks.com/topic/176925-solved-passing-links-through-php-table/#findComment-933081 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.