0

I have some ads in a PHP file, which I simply include. (4 Images in an array and a little array_rand function).

In Chrome and Firefox, the PHP output/images don't show up in HTML. The expected HTML output is simply not there nor do I get an error message.

I have also tried to simply show 1 raw HTML-Tag/Image instead of the random function. Nothing in Chrome and Firefox - Opera, Safari and IE show the ads the way they should.

I have never encountered such an weird behaviour, since I don't get any PHP errors.

Page/error can be seen here: http://beta.com4tires.de/partner-werden.php

<?php

$input = array(
'<a href="http://www.advanti-racing.de/pages/deutsch/produkte/turba.php" target="_blank"
  class="bannerLink"><img src="img/ads/Advanti-Turba.jpg" width="160" height="600"      alt="Advanti Racing - Turba Ad" /></a>',
'<a href="http://www.achilles-reifen.de/pkw-atr-sport-2" target="_blank" class="bannerLink"><img src="img/ads/Achilles-ATR-Sport-2.jpg" width="160" height="600" alt="Achilles Radial - ATR-Sport 2 Ad" /></a>',
'<a href="http://www.enkei.de" target="_blank" class="bannerLink"><img src="img/ads/Enkei-Izumo.jpg" width="160" height="600" alt="Enkei Tuning - Izumo Ad" /></a>',
'<a href="http://www.oxxo-wheels.de/pages/deutsch/produkte/pondora.php" target="_blank" class="bannerLink"><img src="img/ads/OXXO-Pondora.jpg" width="160" height="600" alt="OXXO Alloy Wheels - Turba Ad" /></a>',
'<a href="http://www.com4wheels.de/crossover.html" target="_blank" class="bannerLink"><img src="img/ads/Com4Wheels-Crossover.jpg" width="160" height="600" alt="Com4Wheels - Crossover Ad" /></a>'
);
');

$rand_keys = array_rand($input);
?>
<div class="barBox">
<h2><i class="fa fa-bell"></i>Werbung</h2>
<?php echo $input[$rand_keys]; ?>  
8
  • Can you post the images variable ? Are they stored as paths ? Commented Feb 27, 2014 at 7:49
  • 1
    The ads is there, I think there are some adblock plugins with your browsers. Commented Feb 27, 2014 at 7:52
  • When in PHP and debugging, var_dump is a much better way of seeing what any variable is, both type and contents. Commented Feb 27, 2014 at 7:53
  • Thank you all, I'll check the output by var_dump and give some feedback. Commented Feb 27, 2014 at 7:54
  • 2
    I can't believe I'm blocking my own ads.. this is so embarrassing.. delete this post.. jeezuz.. Thank you Andrew.. I should sell Hamburgers.. Commented Feb 27, 2014 at 7:57

1 Answer 1

1

At default, array_rand picks one key from the given array. So $rand_keys is in your specific case is just one key randomly selected from the $input array. As I can see on your site (given link), there is one ad showing up which is expected. array_rand can have a second argument, which is the required number of keys from the given array.

php.net/array_rand

<?php
$input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
$rand_keys = array_rand($input, 2);
echo $input[$rand_keys[0]] . "\n";
echo $input[$rand_keys[1]] . "\n";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.