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?? Quote Link to comment 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; } Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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... Quote Link to comment 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~ Quote Link to comment 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. 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.