user2424222
user2424222

Reputation:

php swallows code / no output in HTML / no error

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]; ?>  

Upvotes: 0

Views: 85

Answers (1)

hattila
hattila

Reputation: 500

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";

Upvotes: 1

Related Questions