Rianna Posted September 3, 2006 Share Posted September 3, 2006 Hello, I would like to change some php to calling on something by day.The one I have only calls on something randomly. Do you know how I canalter this string to accomodate this? Thanks! $banner_no = (rand()%(count($s_con)-1));Just so you know what the above does, gets a random number which is in the content of my file. for instance if I have 1-some text2-different text3-some other textIt grabs one of these numbers and the text along with it to display randomly. I would like it to display by day and in order instead. Link to comment https://forums.phpfreaks.com/topic/19561-need-help-with-php-random-string-please/ Share on other sites More sharing options...
zq29 Posted September 3, 2006 Share Posted September 3, 2006 If you number them 0 - 6, zero being Sundays text and 6 being Saturdays text, you can grab todays text with date("w"). Link to comment https://forums.phpfreaks.com/topic/19561-need-help-with-php-random-string-please/#findComment-85073 Share on other sites More sharing options...
Rianna Posted September 4, 2006 Author Share Posted September 4, 2006 Not sure what you mean, can you show me a string for this please, to use instead of mine. Thank you very much! Link to comment https://forums.phpfreaks.com/topic/19561-need-help-with-php-random-string-please/#findComment-85550 Share on other sites More sharing options...
Jenk Posted September 4, 2006 Share Posted September 4, 2006 [code]<?php$days = array( 'Sundays text', 'Mondays text, /* etc */ 'Saturdays text');echo $days[array_rand($days)];?>[/code] Link to comment https://forums.phpfreaks.com/topic/19561-need-help-with-php-random-string-please/#findComment-85609 Share on other sites More sharing options...
zq29 Posted September 4, 2006 Share Posted September 4, 2006 [quote author=Rianna link=topic=106716.msg427550#msg427550 date=1157348033]Not sure what you mean, can you show me a string for this please, to use instead of mine. Thank you very much![/quote]Sure, your file would contain:0-Sundays text1-Mondays text2-Tuesdays text3-Wednesdays text4-Thursdays text5-Fridays text6-Saturdays textAnd to get todays text, you'd do something like this:$banner_no = date("w"); Link to comment https://forums.phpfreaks.com/topic/19561-need-help-with-php-random-string-please/#findComment-85644 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.