|   |   |   | ||||
| Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. | 
|    | 
| 
 | |||||||
| Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. | 
|  | Thread Tools | 
|  12-23-2008, 06:16 PM | #1 | 
| Confirmed User Industry Role:  Join Date: Aug 2003 Location: Canada 
					Posts: 2,310
				 |  PHP: Displaying random lines from text file I want to display thumb links randomly from a text file in php. here's a sample link: Code: <a href="../models/samantha/" class="tip thumb"><img src="../models/samantha/thumb.jpg" width="88" height="88"><span>Samantha</span></a> | 
|   |           | 
|  12-23-2008, 06:18 PM | #2 | 
| Confirmed User Join Date: Apr 2003 Location: Loveland, CO 
					Posts: 5,526
				 | <?php echo array_rand(file('../path/to/text.txt')); ?> shit. i suck. thus a bump for you. 
				__________________ Your post count means nothing. | 
|   |           | 
|  12-23-2008, 06:20 PM | #3 | 
| Confirmed User Join Date: Mar 2006 
					Posts: 1,196
				 | PHP Code: 
			 | 
|   |           | 
|  12-23-2008, 06:25 PM | #4 | 
| Confirmed User Industry Role:  Join Date: Aug 2003 Location: Canada 
					Posts: 2,310
				 | |
|   |           | 
|  12-23-2008, 06:35 PM | #5 | |
| Confirmed User Join Date: Mar 2006 
					Posts: 1,196
				 | Quote: 
 is the path correct? try adding a print_r($a); after the file function to see whats in there. | |
|   |           | 
|  12-23-2008, 06:42 PM | #6 | 
| Confirmed User Industry Role:  Join Date: Aug 2003 Location: Canada 
					Posts: 2,310
				 | after adding print_r($a); it displays the thumb link but the error still remains... any ideas? | 
|   |           | 
|  12-23-2008, 06:50 PM | #7 | 
| Confirmed User Join Date: Mar 2006 
					Posts: 1,196
				 | sorry to ask: is there a $ next to the a in the array_rand() function? $b=array_rand($a); short of that, no- i have no idea. | 
|   |           | 
|  12-23-2008, 06:54 PM | #8 | 
| Confirmed User Join Date: Apr 2003 Location: Loveland, CO 
					Posts: 5,526
				 | Are you editing your text file of random lines on a windows box and pushing it to a unix box or vice-versa? Maybe your text file's all torqued up. Try something simple like just a line of: a b c d e f and see what happens. 
				__________________ Your post count means nothing. | 
|   |           | 
|  12-23-2008, 07:10 PM | #9 | |
| Confirmed User Industry Role:  Join Date: Aug 2003 Location: Canada 
					Posts: 2,310
				 | Quote: 
 that worked but it's only displaying 1 letter at a time.. i want all displayed randomly side-by-side. why doesn't the txt like my a href links? | |
|   |           | 
|  12-23-2008, 07:20 PM | #10 | 
| Too lazy to set a custom title Industry Role:  Join Date: Aug 2002 
					Posts: 55,372
				 | Code: <? // urls.txt should be format of <a href="domain.com"><img src="domain.jpg"></a> // 1 per line $file = "urls.txt"; $fp = file($file); srand((double)microtime()*1000000); $urls = $fp[array_rand($fp)]; echo $urls; ?> 
				__________________ Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.  WP Stuff | 
|   |           | 
|  12-23-2008, 07:40 PM | #11 | |
| Confirmed User Join Date: Mar 2006 
					Posts: 1,196
				 | Quote: 
 for some reason i thought you only wanted one line... PHP Code: 
			 | |
|   |           | 
|  12-23-2008, 07:40 PM | #12 | |
| Confirmed User Industry Role:  Join Date: Aug 2003 Location: Canada 
					Posts: 2,310
				 | Quote: 
 displays one thumb at a time. how can we display them ALL side-by-side randomly? | |
|   |           | 
|  12-23-2008, 07:45 PM | #13 | |
| Confirmed User Industry Role:  Join Date: Aug 2003 Location: Canada 
					Posts: 2,310
				 | Quote: 
 what should the txt file look like? samantha thumb.jpg text here? | |
|   |           | 
|  12-23-2008, 07:45 PM | #14 | |
| Confirmed User Join Date: Apr 2003 Location: Loveland, CO 
					Posts: 5,526
				 | Quote: 
 $deck = file('test.txt'); shuffle($deck); echo implode(' ',$deck); 
				__________________ Your post count means nothing. | |
|   |           | 
|  12-23-2008, 07:54 PM | #15 | 
| Confirmed User Join Date: Mar 2006 
					Posts: 1,196
				 | samantha jenny debbie susan christy ... ... julia | 
|   |           | 
|  12-23-2008, 07:54 PM | #16 | |
| Confirmed User Industry Role:  Join Date: Aug 2003 Location: Canada 
					Posts: 2,310
				 | Quote: 
 That worked... thanks!... nice & short too... Thanks to everyone else that helped aswell! Much appreciated!  I just hope this phrases fast when 50 or so entries are added to the txt file... | |
|   |           | 
|  12-23-2008, 07:56 PM | #17 | 
| Confirmed User Join Date: Mar 2006 
					Posts: 1,196
				 | correction: use shuffle($a); not array_shuffle($a); i invented a function i guess :D | 
|   |           | 
|  12-23-2008, 08:07 PM | #18 | 
| Confirmed User Join Date: Apr 2003 Location: Loveland, CO 
					Posts: 5,526
				 | This eMonk thread should be pinned somewhere. It's a very simple question that had a pretty simple solution. However, the communication between ALL involved just wasn't "right" which is the reason it took a while to solve. There's a lesson here kids, and it's not about how to properly sniff your own ass crack, you crazy monkeys, you. 
				__________________ Your post count means nothing. | 
|   |           | 
|  12-23-2008, 08:25 PM | #19 | 
| Confirmed User Industry Role:  Join Date: Aug 2003 Location: Canada 
					Posts: 2,310
				 | thanks again... i'm still new to php... reading my way through, "PHP and MySQL Web Development 4th edition" which is a GREAT book btw, and I knew the method wouldn't be too much lines of code for this task. I also believe it's bad practice to use PHP to display HTML. | 
|   |           | 
|  12-23-2008, 08:27 PM | #20 | 
| Confirmed User Join Date: Mar 2006 
					Posts: 1,196
				 | in my opinion, it really depends on the situation. sometimes you just gotta loop.  | 
|   |           | 
|  12-23-2008, 08:28 PM | #21 | 
| MOBILE PORN: IMOBILEPORN Join Date: Jan 2004 Location: Tinseltown NL 
					Posts: 16,502
				 | Easy peasy. | 
|   |           | 
|  12-23-2008, 08:29 PM | #22 | 
| ♥ ♦ ♣ ♠ Industry Role:  Join Date: Sep 2002 
					Posts: 10,592
				 | Code: <?php include("myrandomtextfile.txt"); ?>
				__________________      "I'm selflessly supporting the common good, but only coincidentally looking out for No.1." | 
|   |           | 
|  12-23-2008, 08:33 PM | #23 | 
| Confirmed User Industry Role:  Join Date: Aug 2003 Location: Canada 
					Posts: 2,310
				 | |
|   |           | 
|  12-23-2008, 08:51 PM | #24 | |
| Confirmed User Join Date: Apr 2003 Location: Loveland, CO 
					Posts: 5,526
				 | Quote: 
 If you get comfortable with a skill, can communicate with a client on how to apply that skill, and can get both you and a client to agree and understand terms on the skill you apply please let me know. :-) 
				__________________ Your post count means nothing. | |
|   |           | 
|  12-23-2008, 09:14 PM | #25 | |
| Confirmed User Join Date: Mar 2006 
					Posts: 1,196
				 | Quote: 
  i learned a couple things... a) read the first post COMPLETELY before you try to help. b) array_shuffle() is not a function. c) PHP and MySQL Web Development 4th edition is a GREAT book. | |
|   |           | 
|  12-23-2008, 09:30 PM | #26 | |
| Confirmed User Join Date: Apr 2003 Location: Loveland, CO 
					Posts: 5,526
				 | Quote: 
 Regardless. I like my crab cioppino served with warm garlic bread. Huh? 
				__________________ Your post count means nothing. | |
|   |           | 
|  12-23-2008, 09:32 PM | #27 | |
| MOBILE PORN: IMOBILEPORN Join Date: Jan 2004 Location: Tinseltown NL 
					Posts: 16,502
				 | Quote: 
 PHP Code: 
			 | |
|   |           | 
|  12-23-2008, 10:00 PM | #28 | 
| Confirmed User Industry Role:  Join Date: Aug 2003 Location: Canada 
					Posts: 2,310
				 | Yeah, I could have been more clear in my original post. I never did mention to output ALL the links at once. Could have added more lines in the sample link aswell.  However this is great... GFY PHP Support Group!  | 
|   |           | 
|  12-24-2008, 02:43 AM | #29 | 
| Registered User Join Date: Apr 2008 Location: underground 
					Posts: 251
				 | try this: $fp=file('yourfile.txt'); shuffle($fp); echo $fp[0]; This should do it. If you want to see more echo $fp[1]; echo $fp[2]; ... | 
|   |           | 
|  12-24-2008, 03:01 AM | #30 | 
| Confirmed User Join Date: Feb 2002 Location: ICQ: 251425 Fr/Au/Ca 
					Posts: 6,863
				 | OK. Seeing as noone else has solved this yet. (IE, haven't used the 'FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES' flags, meaning output would be fubar) PHP Code: 
			Code: <a href="../models/silvia/" class="tip thumb"><img src="../models/silvia/thumb.jpg" width="88" height="88"><span>Silvia</span></a> <a href="../models/billy/" class="tip thumb"><img src="../models/billy/thumb.jpg" width="88" height="88"><span>Billy</span></a> <a href="../models/jenna/" class="tip thumb"><img src="../models/jenna/thumb.jpg" width="88" height="88"><span>Jenna</span></a> <a href="../models/adam/" class="tip thumb"><img src="../models/adam/thumb.jpg" width="88" height="88"><span>Adam</span></a> | 
|   |           |