/    Sign up×
Community /Pin to ProfileBookmark

i have a counter script on my page (courtesy of david harrison) but when i try to implement it i get the following message:

[QUOTE]

Warning: array_rand() [function.array-rand]: First argument has to be an array in …/plugins/randomheader.php on line 41

[/QUOTE]

any suggestions on what this might mean? line 41 ends up being one line in the array itself

[code=php]<?php
$count_file_path = “counter.txt”;

if( file_exists($count_file_path) ){

$count_file = fopen($count_file_path, “r”) or die(“”);
$curr_count = fgets($count_file);
fclose($count_file);

settype( $curr_count, “integer”);
$curr_count = abs($curr_count);
$curr_count++;

$count_file = fopen($count_file_path, “w”) or die(“”);
fwrite($count_file, $curr_count);
fclose($count_file);

} else {

$curr_count = false;

}

$phrases = array();

$phrases[sizeof($phrases)] = “Visitors have lost a collective.$curr_count IQ points by visiting this site.”;
$phrases[sizeof($phrases)] = “$curr_count people prefer McDonald’s to a lifetime of torture.”;
/* more phrases, etc.
the phrases take up lines 34-65
*/

$counter_phrase = ($curr_count) ? $phrases[mt_rand(0, sizeof($phrases)-1)] : “” ;

?>[/code]

to post a comment
PHP

14 Comments(s)

Copy linkTweet thisAlerts:
@NogDogDec 24.2005 — I don't see any call to array_rand() in your code snippet. Which line is line 41?
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYDec 24.2005 — 

could you post the whole code?
--


[I]edit[/I]: oops
Copy linkTweet thisAlerts:
@rhsundergroundauthorDec 24.2005 — could you post the whole code?
[/QUOTE]

[code=php]<?php
/*
Plugin Name: Witty Counter
Plugin URI: #
Description: Uses a text file to create a random counter.
Version: X
Author: David Harrison
Author URI: http://hddkillers.com/
*/
$count_file_path = "counter.txt";

if( file_exists($count_file_path) ){

$count_file = fopen($count_file_path, "r") or die("");
$curr_count = fgets($count_file);
fclose($count_file);

settype( $curr_count, "integer");
$curr_count = abs($curr_count);
$curr_count++;

$count_file = fopen($count_file_path, "w") or die("");
fwrite($count_file, $curr_count);
fclose($count_file);

} else {

$curr_count = false;

}

$phrases = array();

$phrases[sizeof($phrases)] = "Visitors have lost a collective.$curr_count IQ points by visiting this site.";
$phrases[sizeof($phrases)] = "$curr_count people prefer McDonald's to a lifetime of torture.";
$phrases[sizeof($phrases)] = "In the last hour, $curr_count Vietnamese children have starved because you spent your time here instead of helping them.";
$phrases[sizeof($phrases)] = "Skinner A La Mód. helping $curr_count people worldwide to keep their virginity.";
$phrases[sizeof($phrases)] = "$curr_count Republicans saved since May, 2004.";
$phrases[sizeof($phrases)] = "$curr_count animals were brutally harmed while making this site, and 13 nicely harmed.";
$phrases[sizeof($phrases)] = "The hairs on my chest now number $curr_count.";
/* LINE 41 */$phrases[sizeof($phrases)] = "$curr_count cute forest creatures are burned every second in order to power our server.";
$phrases[sizeof($phrases)] = "Skinner A La Mód, now with $curr_count more carcinogens!.";
$phrases[sizeof($phrases)] = "$curr_count suckers have been to this site, and you as well.";
$phrases[sizeof($phrases)] = "Currently insulting $curr_count minority groups.";
$phrases[sizeof($phrases)] = "Books, now $curr_count times better.";
$phrases[sizeof($phrases)] = "$curr_count happy customers since MAy, 2004, and 7 unhappy.";
$phrases[sizeof($phrases)] = "$curr_count forest fires started since my childhood.";
$phrases[sizeof($phrases)] = "So far $curr_count babies have been eaten by Skinner A La Mód staff.";
$phrases[sizeof($phrases)] = "Since May 2004, $curr_count children have been burnt at the stake while their young mothers watched in horror.";
$phrases[sizeof($phrases)] = "By this time next year, we plan to have released $curr_count pedophiles on technicalities.";
$phrases[sizeof($phrases)] = "$curr_count hours of my life have been wasted on Minesweeper since May 2004.";
$phrases[sizeof($phrases)] = "$curr_count hookers have been shot with a shotgun for my pleasure.";
$phrases[sizeof($phrases)] = "$curr_count appendix transplants were accidentally carried out during the making of this site.";
$phrases[sizeof($phrases)] = "It has been $curr_count seconds since I last saw my face without hair.";
$phrases[sizeof($phrases)] = "$curr_count midgets are employed by Skinner A La Mód purely for entertainment.";
$phrases[sizeof($phrases)] = "Megan smells $curr_count times worse than a rotting cabbage.";
$phrases[sizeof($phrases)] = "$curr_count people had their faces replaced with pancakes last year.";
$phrases[sizeof($phrases)] = "$curr_count dangerous scientific experiments were carried out on visitors last year, without them noticing.";
$phrases[sizeof($phrases)] = "Already this year, $curr_count excrement ice creams have been sold to the unsuspecting public.";
$phrases[sizeof($phrases)] = "$curr_count men find aural sex pleasurable.";
$phrases[sizeof($phrases)] = "Skinner A La Mód, because $curr_count encarcerated youth can't be wrong!";
$phrases[sizeof($phrases)] = "$curr_count virgins have been sacrificed to the gods with a cheese grater..";
$phrases[sizeof($phrases)] = "Skinner A La Mód, now with $curr_count more smell!";
$phrases[sizeof($phrases)] = "Skinner A La Mód, now with $curr_count percent less fat!";
$phrases[sizeof($phrases)] = "If you put all the hairs on my body end to end, they would encircle the earth $curr_count times.";

$counter_phrase = ($curr_count) ? $phrases[mt_rand(0, sizeof($phrases)-1)] : "" ;

?>[/code]

it is called as such:
[code=html]<li>
<?php $counter_phrase;?>
</li>[/code]
Copy linkTweet thisAlerts:
@NogDogDec 24.2005 — Runs with no problem on my PC. ? Are there any other php files being included/required somewhere on the page?
Copy linkTweet thisAlerts:
@rhsundergroundauthorDec 24.2005 — dozens. it's implemented on my wordpress.

http://www.skinneralamod.com/wordpress/

edit: this is the use:
[code=php] <div id="sidebar">
<ul>


<li><h2>A little something about me...</h2>
<p>I'm a muscian from Nebraska who likes to play with the internet. <a href="http://skinneralamod.com/wordpress/?page_id=4">Read more...</a></p>
</li>
<li>
--------<br />
<?php witty('');?><br />
--------
</li>
<li>
<?php $counter_phrase;?>
</li>

<li>
<?php /* If this is a 404 page */ if (is_404()) { ?>
<?php /* If this is a category archive */ } elseif (is_category()) { ?>
<p>You are currently browsing the archives for the <?php single_cat_title(''); ?> category.</p>

<?php /* If this is a yearly archive */ } elseif (is_day()) { ?>
<p>You are currently browsing the <a href="<?php echo get_settings('siteurl'); ?>"><?php echo bloginfo('name'); ?></a> weblog archives
for the day <?php the_time('l, F jS, Y'); ?>.</p>

<?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
<p>You are currently browsing the <a href="<?php echo get_settings('siteurl'); ?>"><?php echo bloginfo('name'); ?></a> weblog archives
for <?php the_time('F, Y'); ?>.</p>

<?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
<p>You are currently browsing the <a href ="<?php echo get_settings('siteurl'); ?>"><?php echo bloginfo('name'); ?></a> weblog archives
for the year <?php the_time('Y'); ?>.</p>

<?php /* If this is a monthly archive */ } elseif (is_search()) { ?>
<p>You have searched the <a href="<?php echo get_settings('siteurl'); ?>"><?php echo bloginfo('name'); ?></a> weblog archives
for <strong>'<?php echo wp_specialchars($s); ?>'</strong>. If you are unable to find anything in these search results, you can try one of these links.</p>

<?php /* If this is a monthly archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
<p>You are currently browsing the <a href="<?php echo get_settings('siteurl'); ?>"><?php echo bloginfo('name'); ?></a> weblog archives.</p>

<?php } ?>
</li>

<?php wp_list_pages('title_li=<h2>Pages</h2>' ); ?>

<li><h2>Archives</h2>
<ul>
<?php wp_get_archives('type=monthly'); ?>
</ul>
</li>

<li><h2>Categories</h2>
<ul>
<?php wp_list_cats('sort_column=name&optioncount=1&hierarchical=0'); ?>
</ul>
</li>



<?php /* If this is the frontpage */ if ( is_home() || is_page() ) { ?>
<?php get_links_list(); ?>

<li><h2>Meta</h2>
<ul>
<?php wp_register(); ?>
<li><?php wp_loginout(); ?></li>
<li><a href="http://validator.w3.org/check/referer" title="This page validates as XHTML 1.0 Transitional">Valid <abbr title="eXtensible HyperText Markup Language">XHTML</abbr></a></li>
<li><a href="http://gmpg.org/xfn/"><abbr title="XHTML Friends Network">XFN</abbr></a></li>
<li><a href="http://wordpress.org/" title="Powered by WordPress, state-of-the-art semantic personal publishing platform.">WordPress</a></li>
<?php wp_meta(); ?>
</ul>
</li>
<li>
<?php include (TEMPLATEPATH . '/searchform.php'); ?>
</li>
<?php } ?>

</ul>
</div>
[/code]
Copy linkTweet thisAlerts:
@SpectreReturnsDec 24.2005 — There is no array_rand in any of the code that you posted. You are using mt_rand to get a random number for the element of the array. The original error specifies that you have your arguments wrong, the first one is not an array.

And also:
[code=php]$phrases[sizeof($phrases)] = "The hairs on my chest now number $curr_count.";[/code][/QUOTE]
Could be broken down to:
[code=php]$phrases[] = "The hairs on my chest now number $curr_count.";[/code]
Copy linkTweet thisAlerts:
@CytaelDec 24.2005 — I'm admittedly very very new to PHP and haven't really played around with arrays at all, but assuming PHP arrays are zero-indexed like most other languages, wouldn't sizeof($phrases) return a value 1 past the end of the array? Or are PHP arrays dynamically sized? *shrug*
Copy linkTweet thisAlerts:
@ShrineDesignsDec 25.2005 — you can (should) use [I]$array[] = value[/I] instead of [I]$array[sizeof($array)] = value[/I] to do an append
Copy linkTweet thisAlerts:
@David_HarrisonDec 25.2005 — This oughta do it.

__________________

Installation:

  • * Open counter.php and configure the phrases to your liking.

  • * Copy and paste counter.php and counter.txt into your wp-content/plugins folder.

  • * In the Wordpress admin panel, activate the plugin.

  • * Place the code below in your template wherever you want the counter to appear.


  • <?php if (function_exists('witty_count')) { ?>

    <p>

    <?php witty_count(); ?>

    </p>

    <?php } ?>

    [upl-file uuid=fd29675d-62c6-421a-9422-9c0a0befa7b2 size=2kB]witty_counter.zip[/upl-file]
    Copy linkTweet thisAlerts:
    @LiLcRaZyFuZzYDec 25.2005 — haha, those phrases are hilarious, did you write them, david?
    Copy linkTweet thisAlerts:
    @Daniel_TDec 25.2005 — I think I know the problem... the HTML is outputted within a function inside Wordpress, if I remember correctly. Therefore, you should either make a function return a random phrase and call the function instead of $counter_phrase, or else you could just [url=http://www.php.net/define]define()[/url] the random phrase.

    [b]edit[/b]

    I may have just reanswered the question, but I kind of just skimmed over the thread in the first place.
    Copy linkTweet thisAlerts:
    @David_HarrisonDec 25.2005 — The original version of that was written about a year and a half ago, and in ASP. [url=http://www28.brinkster.com/probes/]That site[/url] is still online actually, I shudder at it's bad design.

    These are the phrases that were used on that site's successor, which ironically, is no longer online anymore. (I've removed the ones that wouldn't be suitable for the forum.)

    Some are the same, but most of them are Ben's, so you'll have to redirect your kudos to the hairy guy.

    [upl-file uuid=e637e1d4-3090-4c75-8b98-96f10d258713 size=2kB]counter_phrases.txt[/upl-file]
    Copy linkTweet thisAlerts:
    @Daniel_TDec 25.2005 — I've removed the ones that wouldn't be suitable for the forum.[/QUOTE]
    I wasn't aware of ANY from QR that were suitable for the forum... ?
    Copy linkTweet thisAlerts:
    @rhsundergroundauthorDec 26.2005 — problem cleared up. thanks all.
    ×

    Success!

    Help @rhsunderground spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.4,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,

    tipper: @Samric24,
    tipped: article
    amount: 1000 SATS,
    )...