can php do this?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

can php do this?

Post 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?
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: can php do this?

Post by requinix »

shuffle

What's with the object-oriented requirement?
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: can php do this?

Post by Vegan »

shuffle(amazonads); // shuffle randomizes fairly
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: can php do this?

Post by requinix »

...?
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: can php do this?

Post 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
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: can php do this?

Post 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.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: can php do this?

Post 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
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: can php do this?

Post 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?
User avatar
mecha_godzilla
Forum Contributor
Posts: 375
Joined: Wed Apr 14, 2010 4:45 pm
Location: UK

Re: can php do this?

Post 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 :mrgreen: 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
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: can php do this?

Post 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.
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
mecha_godzilla
Forum Contributor
Posts: 375
Joined: Wed Apr 14, 2010 4:45 pm
Location: UK

Re: can php do this?

Post 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
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: can php do this?

Post 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;
}
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: can php do this?

Post by requinix »

Once again, shuffle. If that doesn't solve your problem then please explain why not.
annaharris
Forum Commoner
Posts: 30
Joined: Mon Mar 25, 2013 6:52 am

Re: can php do this?

Post by annaharris »

I am agreed with " requinix". Shuffle will solve your problem.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: can php do this?

Post by Vegan »

i guess that will work ok, I am only moving to PHP slowly as its a whole new game
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
Post Reply