I found this ad rotator script and I want to nest JavaScript inside like this below. I get errors thrown how would I accomplish this.
<?php
// random number 1 - 100 $result_random = rand(1, 100);
// if result less than or equal 70, display ad1 (70%)
if($result_random <= 70){
echo "<script type='text/javascript' src='http://myads.com'></script>";
}
// if result less than or equal 90, display ad2 (20%)
else if($result_random <= 90){
echo "<script type='text/javascript' src='http://myads.com'></script>";
}
// if result less than or equal 100, display ad3 (10%)
else {
echo "<script type='text/javascript' src='http://myads.com'></script>";
}
You can use PHP to output the script source to the user’s browser, but you can’t just include and run Javascript inside of a PHP application.
Your output of:
Is the correct behavior. The client would then try to include that script source.
If you’re going to do conditional includes, you’ll want to echo those out between the head tags of your page: