Page 1 of 1
can php do this?
Posted: Thu Mar 21, 2013 5:53 pm
by Vegan
I have this JavaScript function
Code: Select all
function shuffle(array) {
var m = array.length, t, i;
while (m) { // While there remain elements to shuffle ...
i = Math.floor(Math.random() * m--); // Pick a remaining element ...
t = array[m]; // And swap it with the current element...
array[m] = array[i];
array[i] = t;
}
return array;
}
can PHP so this and be as object oriented?
Re: can php do this?
Posted: Thu Mar 21, 2013 5:58 pm
by requinix
shuffle
What's with the object-oriented requirement?
Re: can php do this?
Posted: Thu Mar 21, 2013 6:03 pm
by Vegan
shuffle(amazonads); // shuffle randomizes fairly
Re: can php do this?
Posted: Thu Mar 21, 2013 6:23 pm
by requinix
...?
Re: can php do this?
Posted: Thu Mar 21, 2013 7:51 pm
by Vegan
my goal is to beat up on ad blockers as much as possible
I developed a javascript tool to detect blocking and redirect to my legals page for information on copyright infringement
what I wanted to do is move more javascript to PHP using even plain text files, as all my ads are simple index values at the moment
I can do functions OK with PHP but its hard to find the right approach sometimes
the class idea is overkill, simpler functions is all i need
Re: can php do this?
Posted: Thu Mar 21, 2013 8:09 pm
by requinix
Okay... What does that have to do with shuffling arrays? What's your question?
Also, if you make it so that I can't use your site if I block ads, I won't use your site. Just a heads up.
Re: can php do this?
Posted: Thu Mar 21, 2013 8:26 pm
by Vegan
shuffling the ads so that I can show different ads within classes
the technique I use is mainly studied from card playing
I was also thinking about make the page load time faster
I expect the redirect to legals will be the most popular page soon, you can add an exception to the blocker to unblock and then the site works fine
Re: can php do this?
Posted: Thu Mar 21, 2013 9:03 pm
by requinix
Okay, well, I'd bet that array_rand() is better suited to your purposes but shuffle() may be more appropriate depending on a lot of details which you don't seem to want to give.
What's your code now and what does it need to do?
Re: can php do this?
Posted: Fri Mar 22, 2013 5:23 pm
by mecha_godzilla
Just a thought, but if I was an advertiser purchasing space on your site I'd want some reassurance that whether or not my ads are displayed isn't subject to some random arbitrary algorithm

Normally, ad space would be sold on the number of page impressions, so you should be keeping a count of how often those ads appear and then deactivating them after the maximum number of page impressions has been reached.
Also, how is not wanting to see your ads a form of copyright infringement? Perhaps a breach of the site's terms and conditions maybe, but this still seems rather draconian and - as requinix has suggested - I'd go elsewhere if your site stopped me accessing it or displayed some legal notice. Also, how does that look from the advertisers' perspective? There is too much competition from other sites to risk losing valuable visitors. And what if the ad-blocking isn't opt-in - let's say the visitor is using an Internet cafe or Wi-Fi network where the firewall blocks this kind of content, or a work computer where the IT support have installed it by default?
HTH,
Mecha Godzilla
Re: can php do this?
Posted: Fri Apr 05, 2013 10:42 pm
by Vegan
Ad blocking is now so pervasive I had to do something to keep some $ flowing in, video cards are expensive
I reconcile my server logs with google and my ad agency all to see if current countermeasures are effective or not and if I need to get back to the drawing board.
The internet economy depends on income from ads, just like TV, radio and so on.
Re: can php do this?
Posted: Sat Apr 06, 2013 11:08 am
by mecha_godzilla
I certainly don't disagree with the point you're making, but I don't think it's viable to specifically exclude people from a site just because they don't want to see your ads - a permissive policy would be much better, and (as an example) although I am well aware of the existence of ad blockers, I don't install them in my browsers because I understand that some sites rely on ads for their income. Similarly, I won't listen to a radio station if their advertising is too pervasive or visit a site if their advertising methods are too aggressive. Whether or not these advertising models are sustainable is not really my concern unless I'm reliant on that service, so it's better to "reward" loyalty and not "punish" disloyalty - even if a person is being "disloyal" by blocking your advertising, they might recommend your site to someone else who isn't or (in the wider scheme of things) improve your position with advertisers because the demographics of your site are much better and the audience larger as a result of accommodating "disloyal" visitors.
M_G
Re: can php do this?
Posted: Tue May 28, 2013 5:24 pm
by Vegan
anyway back to the task at hand
my function takes an array as its argument and it returns one
so can PHP do that OK or do I need to tweak the code a bit....
Code: Select all
function shuffle(array) {
var m = array.length, t, i;
while (m) { // While there remain elements to shuffle ...
i = Math.floor(Math.random() * m--); // Pick a remaining element ...
t = array[m]; // And swap it with the current element...
array[m] = array[i];
array[i] = t;
}
return array;
}
Re: can php do this?
Posted: Tue May 28, 2013 6:19 pm
by requinix
Once again,
shuffle. If that doesn't solve your problem then please explain why not.
Re: can php do this?
Posted: Sat Jun 01, 2013 6:42 am
by annaharris
I am agreed with " requinix". Shuffle will solve your problem.
Re: can php do this?
Posted: Thu Jun 06, 2013 4:31 pm
by Vegan
i guess that will work ok, I am only moving to PHP slowly as its a whole new game