Setting javascript inside of php for Mobfox backfill
I'm using Mobfox as my primary ad network for a mobile app, and have identified the spot where I can backfill:
if (preg_match('<!--NOAD-->', $contents)){
global $no_ad_availible;
$no_ad_availible=true;
}
else
{
$no_ad_availible=false;
}
The script I need inside of there is:
<img src="http://serve.vdopia.com/adserver/tracker.php?m=ti;ci=3708;ai=11010;chid=9762;ou=rd;rand=[timestamp]" style="height:1px;width:1px;position:absolute;visibility:hidden;" />
<script language='javascript' src='http://serve.vdopia.com/adserver/html5/inwapads/?sleepAfter=0;adFormat=banner;ak=acctnumber;version=1.0;cb=[timestamp]'></script>
<noscript><img src="http://serve.vdopia.com/adserver/tracker.php?m=nji;ci=3708;ai=11011;chid=9762;ou=rd;rand=[timestamp]" 开发者_如何学JAVAstyle="height:1px;width:1px;position:absolute;visibility:hidden;" /></noscript>
I've tried everything I can think of, both loading the script from a separate file to inserting it in the code, yet nothing appears.
Obviously I'm not much of a programmer, but trying to learn.
Thanks
You need to echo
the JavaScript and image calls or (even better) temporarily end your PHP... if you simply put them in PHP code, they will be interpreted as PHP.
I can't tell for sure if you want the code to be inserted if $no_ad_available == true or false. Either way, the same concept would apply, I'm going to assume you want it inserted if true. You can use:
<?php
if (preg_match('<!--NOAD-->', $contents)) {
global $no_ad_availible;
$no_ad_availible=true;
?>
<img src="http://serve.vdopia.com/adserver/tracker.php?m=ti;ci=3708;ai=11010;chid=9762;ou=rd;rand=[timestamp]" style="height:1px;width:1px;position:absolute;visibility:hidden;" /> ...Rest of ad insert code
<?php
} else {
$no_ad_availible=false;
}
?>
Good luck.
精彩评论