Chuck D Posted April 27, 2007 Share Posted April 27, 2007 Ok, I need help finding a simple way to get links from a text file and displaying them all linked to an image, and possible randomizing the order too... if you need more info, or can help, it would be much appreciated! I am trying to make it easier on myself because the links change often and it would just save me a lot of time just edite\ing a list instead of a bunch of html something like: link1 link2 link3 link4 then on refresh: link3 link1 link4 link2 and have the list like: link1 link2 link3 link4 I don't think it should be too difficult but I am new to php and cannot find what I am looking for on php.net. thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/49019-solved-randomized-linked-images-urls-in-txt/ Share on other sites More sharing options...
MadTechie Posted April 27, 2007 Share Posted April 27, 2007 use fread what code do you have sop far ? Quote Link to comment https://forums.phpfreaks.com/topic/49019-solved-randomized-linked-images-urls-in-txt/#findComment-240122 Share on other sites More sharing options...
Chuck D Posted April 27, 2007 Author Share Posted April 27, 2007 I pretty much have nothing... I want to get it so I don't have to mess with html as much as possible. Quote Link to comment https://forums.phpfreaks.com/topic/49019-solved-randomized-linked-images-urls-in-txt/#findComment-240127 Share on other sites More sharing options...
MadTechie Posted April 27, 2007 Share Posted April 27, 2007 well we can help with the problem or do you want one written for you ? Quote Link to comment https://forums.phpfreaks.com/topic/49019-solved-randomized-linked-images-urls-in-txt/#findComment-240129 Share on other sites More sharing options...
Chuck D Posted April 27, 2007 Author Share Posted April 27, 2007 yeah if possible... i am trying to figure it out... but yeah id def love some help Quote Link to comment https://forums.phpfreaks.com/topic/49019-solved-randomized-linked-images-urls-in-txt/#findComment-240130 Share on other sites More sharing options...
MadTechie Posted April 27, 2007 Share Posted April 27, 2007 heres a quick one <?php //file of links $filename = "links.txt"; $link = array(); $handle = @fopen($filename, "r"); if ($handle) { while (!feof($handle)) { $buffer = fgets($handle, 4096); // read line by line $link[] = $buffer; //store in array } fclose($handle); } shuffle($link); // mix up the array foreach($link as $l) //loop and print the links { echo "<a href=$l>$l</a> | "; } ?> links.txt http://www.phpfreaks.com/articles.php http://www.phpfreaks.com/tutorials.php http://www.phpfreaks.com/quickcode.php http://www.phpfreaks.com/forums/index.php/topic,138161.0.html normally i would point you to the freelance section but i had a great day this code will probably need cleaning up, but its a start EDIT: Added some comments in the code Quote Link to comment https://forums.phpfreaks.com/topic/49019-solved-randomized-linked-images-urls-in-txt/#findComment-240134 Share on other sites More sharing options...
Chuck D Posted April 27, 2007 Author Share Posted April 27, 2007 hey, thanks a lot... hope the rest of your day is better it works perfect Quote Link to comment https://forums.phpfreaks.com/topic/49019-solved-randomized-linked-images-urls-in-txt/#findComment-240136 Share on other sites More sharing options...
MadTechie Posted April 27, 2007 Share Posted April 27, 2007 i don't think its 100% it will display all the links.. but if its ok please click solved Quote Link to comment https://forums.phpfreaks.com/topic/49019-solved-randomized-linked-images-urls-in-txt/#findComment-240137 Share on other sites More sharing options...
Chuck D Posted April 27, 2007 Author Share Posted April 27, 2007 hmm... i have been playing with it and after the second link its adding a <br> into the link like <a href=whatever.com<br>>whatever.com Quote Link to comment https://forums.phpfreaks.com/topic/49019-solved-randomized-linked-images-urls-in-txt/#findComment-240139 Share on other sites More sharing options...
Chuck D Posted April 28, 2007 Author Share Posted April 28, 2007 ugh... <a href=whatever.com<br>>whatever.com</a> and its not doing that on the last one so im assuming its addinf a br because the txt has them on new lines... but i dont know how to fix what i think its doing is adding the new line onto the end of the link and thats conflicting with the code making it like this: <a href=whatever.com >whatever.com </a> Quote Link to comment https://forums.phpfreaks.com/topic/49019-solved-randomized-linked-images-urls-in-txt/#findComment-240149 Share on other sites More sharing options...
MadTechie Posted April 28, 2007 Share Posted April 28, 2007 foreach($link as $l) //loop and print the links { echo "<a href=$l>$l</a><br>"; } will work also check the txt file (remember use plain text NOT html) Quote Link to comment https://forums.phpfreaks.com/topic/49019-solved-randomized-linked-images-urls-in-txt/#findComment-240155 Share on other sites More sharing options...
Chuck D Posted April 28, 2007 Author Share Posted April 28, 2007 what its doing is putting <a href=whatever.com >whatever.com</a> which shows up on the html page as whatever.com instead of <a href=whatever.com>whatever.com</a> Quote Link to comment https://forums.phpfreaks.com/topic/49019-solved-randomized-linked-images-urls-in-txt/#findComment-240158 Share on other sites More sharing options...
MadTechie Posted April 28, 2007 Share Posted April 28, 2007 ok #1 check the echo "<a href=$l>$l</a><br>"; the <br> AFTER the </a> , if it is (i guess it is), open your txt file in notepad and check you don't have the <br> in their if you still have problems please post the text file and code Quote Link to comment https://forums.phpfreaks.com/topic/49019-solved-randomized-linked-images-urls-in-txt/#findComment-240159 Share on other sites More sharing options...
Chuck D Posted April 28, 2007 Author Share Posted April 28, 2007 i dont have any html in my text file and i copied the code just as you wrote it, its just that it putting the line break after the links, is theyre an array that will make it not read the line break or take it off?... its not any of my coding that has a break code Quote Link to comment https://forums.phpfreaks.com/topic/49019-solved-randomized-linked-images-urls-in-txt/#findComment-240164 Share on other sites More sharing options...
MadTechie Posted April 28, 2007 Share Posted April 28, 2007 Ahhhh ok remove the line breaks from the array.. add them on the display part <?php //file of links $filename = "links.txt"; $link = array(); $handle = @fopen($filename, "r"); if ($handle) { while (!feof($handle)) { $buffer = fgets($handle, 4096); // read line by line $link[] = $buffer; //store in array // <--Keep as is } fclose($handle); } shuffle($link); // mix up the array foreach($link as $l) //loop and print the links { echo "<a href=$l>$l</a> <br> "; //<---------DISPLAY <BR> added } ?> Quote Link to comment https://forums.phpfreaks.com/topic/49019-solved-randomized-linked-images-urls-in-txt/#findComment-240165 Share on other sites More sharing options...
Chuck D Posted April 28, 2007 Author Share Posted April 28, 2007 its still giving me the same result... do you maybe have aim or msn or something? im sorry to make it so difficult Quote Link to comment https://forums.phpfreaks.com/topic/49019-solved-randomized-linked-images-urls-in-txt/#findComment-240167 Share on other sites More sharing options...
MadTechie Posted April 28, 2007 Share Posted April 28, 2007 can you post the code you have, i have MSN but i do prefer to keep it on the board as others may used this as a referance. nb: you don't have to post real info you can remove passwords etc Quote Link to comment https://forums.phpfreaks.com/topic/49019-solved-randomized-linked-images-urls-in-txt/#findComment-240170 Share on other sites More sharing options...
Chuck D Posted April 28, 2007 Author Share Posted April 28, 2007 <?php //file of links $filename = "links.txt"; $link = array(); $handle = @fopen($filename, "r"); if ($handle) { while (!feof($handle)) { $buffer = fgets($handle, 4096); // read line by line $link[] = $buffer; //store in array // <--Keep as is } fclose($handle); } shuffle($link); // mix up the array foreach($link as $l) //loop and print the links { echo "<a href=$l target=_blank><img src=image.gif width=132 height=20 border=1></a>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/49019-solved-randomized-linked-images-urls-in-txt/#findComment-240173 Share on other sites More sharing options...
MadTechie Posted April 28, 2007 Share Posted April 28, 2007 Hummm this worked for me (images across the top) <?php $filename = "links.txt"; $link = array(); $handle = @fopen($filename, "r"); if ($handle) { while (!feof($handle)) { $buffer = fgets($handle, 4096); $link[] = $buffer; } fclose($handle); } shuffle($link); foreach($link as $l) { echo "<a href=$l target=_blank><img src=image.gif width=132 height=20 border=1></a>"; } ?> So did this (image going to down) <?php $filename = "links.txt"; $link = array(); $handle = @fopen($filename, "r"); if ($handle) { while (!feof($handle)) { $buffer = fgets($handle, 4096); $link[] = $buffer; } fclose($handle); } shuffle($link); foreach($link as $l) { echo "<a href=$l target=_blank><img src=image.gif width=132 height=20 border=1></a><br />"; } ?> can you try the link file i have attached [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/49019-solved-randomized-linked-images-urls-in-txt/#findComment-240179 Share on other sites More sharing options...
Chuck D Posted April 28, 2007 Author Share Posted April 28, 2007 here is my msn... and what i can do is post the fix ****@hotmail.com Quote Link to comment https://forums.phpfreaks.com/topic/49019-solved-randomized-linked-images-urls-in-txt/#findComment-240182 Share on other sites More sharing options...
MadTechie Posted April 28, 2007 Share Posted April 28, 2007 OK final code <?php $filename = "links.txt"; $link = array(); $handle = @fopen($filename, "r"); if ($handle) { while (!feof($handle)) { $buffer = fgets($handle, 4096); $link[] = trim($buffer); //added trim } fclose($handle); } shuffle($link); foreach($link as $l) { echo "<a href=$l target=_blank><img src=image.gif width=132 height=20 border=1></a>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/49019-solved-randomized-linked-images-urls-in-txt/#findComment-240190 Share on other sites More sharing options...
Chuck D Posted April 28, 2007 Author Share Posted April 28, 2007 yep it works perfect now thank you! Quote Link to comment https://forums.phpfreaks.com/topic/49019-solved-randomized-linked-images-urls-in-txt/#findComment-240192 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.