목차
php广告加载类用法实例,php加载用法实例
php中类的用法
백엔드 개발 PHP 튜토리얼 php广告加载类用法实例,php加载用法实例_PHP教程

php广告加载类用法实例,php加载用法实例_PHP教程

Jul 13, 2016 am 10:18 AM
php 공시 하다 친절한

php广告加载类用法实例,php加载用法实例

本文实例讲述了php广告加载类的用法,非常实用。分享给大家供大家参考。具体方法如下:

该php广告加载类,支持异步与同步加载。需要使用Jquery实现。

ADLoader.class.php类文件如下:

<&#63;php 
/** 广告加载管理类 
*  Date:  2013-08-04 
*  Author: fdipzone 
*  Ver:  1.0 
* 
*  Func: 
*  public load     加载广告集合 
*  public setConfig  广告配置 
*  private getAds    根据channel创建广告集合 
*  private genZoneId  zoneid base64_encode 处理 
*  private genHtml   生成广告html 
*  private checkBrowser 检查是否需要同步加载的浏览器 
*/ 
 
class ADLoader{ // class start 
 
  private static $_ads = array();   // 广告集合 
  private static $_step = 300;    // 广告加载间隔 
  private static $_async = true;   // 是否异步加载 
  private static $_config = array(); // 广告设置文件 
  private static $_jsclass = null;  // 广告JS class 
 
 
  /** 加载广告集合 
  * @param String $channel 栏目,对应config文件 
  * @param int   $step  广告加载间隔 
  * @param boolean $async  是否异步加载 
  */ 
  public static function load($channel='', $step='', $async=''){ 
    if(isset($step) && is_numeric($step) && $step>0){ 
      self::$_step = $step; 
    } 
 
    if(isset($async) && is_bool($async)){ 
      self::$_async = $async; 
    } 
 
    // 判断浏览器,如IE强制使用同步加载 
    if(!self::checkBrowser()){ 
      self::$_async = false; 
    } 
 
    self::getAds($channel); 
    self::genZoneId(); 
 
    return self::genHtml(); 
  } 
 
  /** 设置config 
  * @param String $config 广告配置 
  * @param String $jsclass js class文件路径 
  */ 
  public static function setConfig($config=array(), $jsclass=''){ 
    self::$_config = $config; 
    self::$_jsclass = $jsclass; 
  } 
 
 
  /** 根据channel创建广告集合 
  * @param String $channel 栏目 
  */ 
  private static function getAds($channel=''){ 
    $AD_Config = self::$_config; 
    if($AD_Config!=null){ 
      self::$_ads = isset($AD_Config[$channel])&#63; $AD_Config[$channel] : $AD_Config['default']; 
    } 
  } 
 
  /** zoneid base64_encode 处理 */ 
  private static function genZoneId(){ 
 
    // 同步加载广告不需要处理zoneid 
    if(!self::$_async){ 
      return ; 
    } 
 
    $ads = self::$_ads; 
    for($i=0,$len=count($ads); $i<$len; $i++){ 
      if(isset($ads[$i]['zoneId'])){ 
        $ads[$i]['zoneId'] = base64_encode('var zoneid='.$ads[$i]['zoneId'].';'); 
      } 
    } 
    self::$_ads = $ads; 
  } 
 
  /** 生成广告html */ 
  private static function genHtml(){ 
    $ads = self::$_ads; 
    $html = array(); 
    if(self::$_jsclass!=null && $ads){ 
      array_push($html, '<script type="text/javascript" src="'.self::$_jsclass.'"></script>'); 
 
      // 同步需要预先加载 
      if(!self::$_async){ 
        foreach($ads as $ad){ 
          array_push($html, '<div id="'.$ad['domId'].'_container" style="display:none">'); 
          array_push($html, '<script type="text/javascript">'); 
          array_push($html, 'ADLoader.preload('.json_encode($ad).');'); 
          array_push($html, '</script>'); 
          array_push($html, '</div>'); 
        } 
      } 
 
      array_push($html, '<script type="text/javascript">'); 
      array_push($html, 'var ads='.json_encode($ads).';'); 
      array_push($html, '$(document).ready(function(){ ADLoader.load(ads, '.self::$_step.', '.intval(self::$_async).'); });'); 
      array_push($html, '</script>'); 
    } 
    return implode("\r\n", $html); 
  } 
 
  /** 判断是否需要强制同步加载的浏览器 */ 
  private static function checkBrowser(){ 
    $user_agent = $_SERVER['HTTP_USER_AGENT']; 
    if(strstr($user_agent,'MSIE')!=''){ 
      return false; 
    } 
    return true; 
  } 
 
} // class end 
&#63;>

로그인 후 복사

ADConfig.php文件如下:

<&#63;php 
/** 广告配置文件 **/ 
 
return array( 
 
  'case_openx' => array( 
    array( 
      'type' => 'openx', 
      'domId' => 'ad_728x90', 
      'zoneId' => 452 
    ), 
    array( 
      'type' => 'openx', 
      'domId' => 'ad_300x250', 
      'zoneId' => 449 
    ), 
    array( 
      'type' => 'openx', 
      'domId' => 'ad_l2_300x250', 
      'zoneId' => 394 
    ), 
  ), 
 
  'case_url' => array( 
    array( 
      'type' => 'url', 
      'domId' => 'ad_728x90', 
      'url' => 'adurl.php&#63;zoneid=452' 
    ), 
    array( 
      'type' => 'url', 
      'domId' => 'ad_300x250', 
      'url' => 'adurl.php&#63;zoneid=449' 
    ), 
    array( 
      'type' => 'url', 
      'domId' => 'ad_l2_300x250', 
      'url' => 'adurl.php&#63;zoneid=394' 
    ) 
  ), 
 
  'case_sync_openx' => array( 
    array( 
      'type' => 'openx', 
      'domId' => 'ad_728x90', 
      'zoneId' => 452 
    ), 
    array( 
      'type' => 'openx', 
      'domId' => 'ad_300x250', 
      'zoneId' => 449 
    ), 
    array( 
      'type' => 'openx', 
      'domId' => 'ad_l2_300x250', 
      'zoneId' => 394 
    ), 
  ), 
 
  'default' => array( 
    array( 
      'type' => 'openx', 
      'domId' => 'ad_728x90', 
      'zoneId' => 452 
    ), 
    array( 
      'type' => 'openx', 
      'domId' => 'ad_300x250', 
      'zoneId' => 449 
    ), 
    array( 
      'type' => 'openx', 
      'domId' => 'ad_l2_300x250', 
      'zoneId' => 394 
    ), 
  ), 
 
); 
 
&#63;>

로그인 후 복사

ADLoader.js文件如下:

/** 异步加载广告 
*  Date:  2013-08-04 
*  Author: fdipzone 
*  Ver:  1.0 
*/ 
var ADLoader = (function(){ 
 
  var _ads = [],   // 广告集合 
    _step = 300,  // 广告加载间隔 
    _async = true, // 是否异步加载 
    _loaded = 0;  // 已经加载的广告数 
   
  /** loadAd 循环加载广告 
  * @param int c 第几个广告 
  */ 
  function loadAD(c){ 
    if(_loaded>=_ads.length){ 
      return ; 
    } 
 
    if($('#'+_ads[c].domId).length>0){ // 判断dom是否存在 
 
      if(_async){ // 异步执行 
 
        crapLoader.loadScript(getScript(_ads[c]), _ads[c].domId, { 
          success: function(){ 
            completeAd(); 
          } 
        }); 
       
      }else{ // 将同步加载的广告显示 
 
        var ad_container = $('#'+_ads[c].domId+'_container'); 
        ad_container.find('embed').attr('wmode','transparent').end().find('object').each(function(k, v){ 
          v.wmode = 'transparent'; // 将flash变透明 
        }); 
        $('#'+_ads[c].domId)[0].appendChild(ad_container[0]); 
        ad_container.show(); 
         
        completeAd(); 
      } 
    }else{ // dom不存在 
      completeAd(); 
    } 
  } 
 
  /** 加载完广告后处理 */ 
  function completeAd(){ 
    _loaded ++; 
    setTimeout(function(){ 
      loadAD(_loaded); 
    }, _step);     
  } 
 
  /** 获取广告 
  * @param Array ad 广告参数 
  */ 
  function getScript(ad){ 
    var ret = null; 
 
    switch(ad.type){ 
      case 'openx': // openx code ad 
        ret = 'data:text/javascript;base64,' + ad.zoneId + 'dmFyIG0zX3UgPSAobG9jYXRpb24ucHJvdG9jb2w9PSdodHRwczonPydodHRwczovL2Fkcy5ubWcuY29tLmhrL3d3dy9kZWxpdmVyeS9hanMucGhwJzonaHR0cDovL2Fkcy5ubWcuY29tLmhrL3d3dy9kZWxpdmVyeS9hanMucGhwJyk7CnZhciBtM19yID0gTWF0aC5mbG9vcihNYXRoLnJhbmRvbSgpKjk5OTk5OTk5OTk5KTsKaWYgKCFkb2N1bWVudC5NQVhfdXNlZCkgZG9jdW1lbnQuTUFYX3VzZWQgPSAnLCc7CmRvY3VtZW50LndyaXRlICgiPHNjciIrImlwdCB0eXBlPSd0ZXh0L2phdmFzY3JpcHQnIHNyYz0nIittM191KTsKZG9jdW1lbnQud3JpdGUgKCI/em9uZWlkPSIgKyB6b25laWQpOwpkb2N1bWVudC53cml0ZSAoJyZhbXA7Y2I9JyArIG0zX3IpOwppZiAoZG9jdW1lbnQuTUFYX3VzZWQgIT0gJywnKSBkb2N1bWVudC53cml0ZSAoIiZhbXA7ZXhjbHVkZT0iICsgZG9jdW1lbnQuTUFYX3VzZWQpOwpkb2N1bWVudC53cml0ZSAoZG9jdW1lbnQuY2hhcnNldCA/ICcmYW1wO2NoYXJzZXQ9Jytkb2N1bWVudC5jaGFyc2V0IDogKGRvY3VtZW50LmNoYXJhY3RlclNldCA/ICcmYW1wO2NoYXJzZXQ9Jytkb2N1bWVudC5jaGFyYWN0ZXJTZXQgOiAnJykpOwpkb2N1bWVudC53cml0ZSAoIiZhbXA7bG9jPSIgKyBlc2NhcGUod2luZG93LmxvY2F0aW9uKSk7CmlmIChkb2N1bWVudC5yZWZlcnJlcikgZG9jdW1lbnQud3JpdGUgKCImYW1wO3JlZmVyZXI9IiArIGVzY2FwZShkb2N1bWVudC5yZWZlcnJlcikpOwppZiAoZG9jdW1lbnQuY29udGV4dCkgZG9jdW1lbnQud3JpdGUgKCImY29udGV4dD0iICsgZXNjYXBlKGRvY3VtZW50LmNvbnRleHQpKTsKaWYgKGRvY3VtZW50Lm1tbV9mbykgZG9jdW1lbnQud3JpdGUgKCImYW1wO21tbV9mbz0xIik7CmRvY3VtZW50LndyaXRlICgiJz48XC9zY3IiKyJpcHQ+Iik7'; 
        break; 
       
      case 'url': // url ad 
        ret = ad.url; 
        break; 
    } 
    return ret; 
  } 
 
  /** 同步加载广告 
  * @param Array ad 广告参数 
  */ 
  function writeAd(ad){ 
    switch(ad.type){ 
      case 'openx': 
        var m3_u = (location.protocol=='https:'&#63;'https://ads.nmg.com.hk/www/delivery/ajs.php':'http://ads.nmg.com.hk/www/delivery/ajs.php'); 
        var m3_r = Math.floor(Math.random()*99999999999); 
        if (!document.MAX_used) document.MAX_used = ','; 
        document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u); 
        document.write ("&#63;zoneid=" + ad.zoneId); 
        document.write ('&cb=' + m3_r); 
        if (document.MAX_used != ',') document.write ("&exclude=" + document.MAX_used); 
        document.write (document.charset &#63; '&charset='+document.charset : (document.characterSet &#63; '&charset='+document.characterSet : '')); 
        document.write ("&loc=" + escape(window.location)); 
        if (document.referrer) document.write ("&referer=" + escape(document.referrer)); 
        if (document.context) document.write ("&context=" + escape(document.context)); 
        if (document.mmm_fo) document.write ("&mmm_fo=1"); 
        document.write ("'><\/scr"+"ipt>"); 
        break; 
       case 'url': 
        document.write ('<script type="text/javascript" src="' + ad.url + '"></script>'); 
        break; 
    } 
  } 
 
  obj = { 
 
    /** 加载广告 
    * @param Array  ads  广告集合 
    * @param int   step 广告加载间隔 
    * @param boolean async true:异步加载 false:同步加载 
    */ 
    load: function(ads, step, async){ 
      _ads = ads; 
 
      if(typeof(step)!='undefined'){ 
        _step = step; 
      } 
 
      if(typeof(async)!='undefined'){ 
        _async = async; 
      } 
 
      loadAD(_loaded); 
    }, 
 
    /** 预加载广告 */ 
    preload: function(ad){ 
      if($('#'+ad.domId).length>0){  // 判断dom是否存在 
        writeAd(ad); 
      } 
    } 
  } 
  return obj; 
 
}()); 
 
/* crapLoader */ 
var crapLoader = (function() { 
   
  var isHijacked = false, 
    queue = [], 
    inputBuffer = [], 
    writeBuffer = {}, 
    loading = 0, 
    elementCache = {}, 
    returnedElements = [], 
    splitScriptsRegex = /(<script[\s\S]*&#63;<\/script>)/gim, 
    globalOptions = { 
      autoRelease: true, 
      parallel: true, 
      debug: false 
    }, 
    defaultOptions = { 
      charset: undefined, 
      success: undefined, 
      func: undefined, 
      src: undefined, 
      timeout: 3000 
    },publ, 
    head = document.getElementsByTagName("head")[0] || document.documentElement, 
    support = { 
      scriptOnloadTriggeredAccurately: false, 
      splitWithCapturingParentheses: ("abc".split(/(b)/)[1]==="b") 
    }; 
   
  function checkQueue () { 
    if(queue.length) { 
      loadScript( queue.shift() ); 
    } else if(loading === 0 && globalOptions.autoRelease) { 
      debug("Queue is empty. Auto-releasing."); 
      publ.release(); 
    } 
  } 
 
  function checkWriteBuffer (obj) { 
    var buffer = writeBuffer[obj.domId], 
      returnedEl; 
 
    if(buffer && buffer.length) { 
      writeHtml( buffer.shift(), obj ); 
 
    } else { 
      while (returnedElements.length > 0) { 
        returnedEl = returnedElements.pop(); 
        var id = returnedEl.id; 
        var elInDoc = getElementById(id); 
        if (!elInDoc) { continue; } 
        var parent = elInDoc.parentNode; 
        elInDoc.id = id + "__tmp"; 
        parent.insertBefore(returnedEl, elInDoc); 
        parent.removeChild(elInDoc); 
      } 
      finished(obj); 
    } 
  } 
 
  function debug (message, obj) { 
    if(!globalOptions.debug || !window.console) { return; } 
    var objExtra = ""; 
    if(obj) { 
      objExtra = "#"+obj.domId+" "; 
      var depth = obj.depth; 
      while(depth--) { objExtra += "  "; } 
    } 
    console.log("crapLoader " + objExtra + message); 
  } 
 
  function extend (t, s) { 
    var k; 
    if(!s) { return t; } 
    for(k in s) { 
      t[k] = s[k]; 
    } 
    return t; 
  } 
 
  function finished (obj) { 
    if(obj.success && typeof obj.success === "function") { 
      obj.success.call( document.getElementById(obj.domId) ); 
    } 
    checkQueue(); 
  } 
 
  function flush (obj) { 
    var domId = obj.domId, 
      outputFromScript, 
      htmlPartArray; 
 
    outputFromScript = stripNoScript( inputBuffer.join("") ); 
    inputBuffer = []; 
 
    htmlPartArray = separateScriptsFromHtml( outputFromScript ); 
 
    if(!writeBuffer[domId]) { 
      writeBuffer[domId] = htmlPartArray; 
    } else { 
      Array.prototype.unshift.apply(writeBuffer[domId], htmlPartArray); 
    } 
    checkWriteBuffer(obj); 
  } 
 
  function getCachedElById (domId) { 
    return elementCache[domId] || (elementCache[domId] = document.getElementById(domId)); 
  } 
 
  function getElementById (domId) { 
    return ( publ.orgGetElementById.call &#63; 
      publ.orgGetElementById.call(document, domId) : 
      publ.orgGetElementById(domId) ); 
  } 
 
  function getElementByIdReplacement (domId) { 
    var el = getElementById(domId), 
      html, frag, div, found; 
 
    function traverseForElById(domId, el) { 
      var children = el.children, i, l, child; 
      if(children && children.length) { 
        for(i=0,l=children.length; i<l; i++) { 
          child = children[i]; 
          if(child.id && child.id === domId) { return child; } 
          if(child.children && child.children.length) { 
            var tmp = traverseForElById(domId, child); 
            if (tmp) return tmp; 
          } 
        } 
      } 
    } 
 
    function searchForAlreadyReturnedEl(domId) { 
      var i, l, returnedEl; 
      for(i=0,l=returnedElements.length; i<l; i++) { 
        returnedEl = returnedElements[i]; 
        if(returnedEl.id === domId) { return returnedEl; } 
      } 
    } 
 
    if(el) { return el; } 
 
    if (returnedElements.length) { 
      found = searchForAlreadyReturnedEl(domId); 
      if (found) { 
        return found; 
      } 
    } 
 
    if(inputBuffer.length) { 
      html = inputBuffer.join(""); 
      frag = document.createDocumentFragment(); 
      div = document.createElement("div"); 
      div.innerHTML = html; 
      frag.appendChild(div); 
      found = traverseForElById(domId, div); 
      if (found) { 
        returnedElements.push(found); 
      } 
      return found; 
    } 
  } 
 
  var globalEval = (function () { 
    return (window.execScript &#63; function(code, language) { 
      window.execScript(code, language || "JavaScript"); 
    } : function(code, language) { 
      if(language && !/^javascript/i.test(language)) { return; } 
      window.eval.call(window, code); 
    }); 
  }()); 
 
  function isScript (html) { 
    return html.toLowerCase().indexOf("<script") === 0; 
  } 
 
  function runFunc (obj) { 
    obj.func(); 
    obj.depth++; 
    flush(obj); 
  } 
 
  function loadScript (obj) { 
    loading++; 
    // async loading code from jQuery 
    var script = document.createElement("script"); 
    if(obj.type) { script.type = obj.type; } 
    if(obj.charset) { script.charset = obj.charset; } 
    if(obj.language) { script.language = obj.language; } 
 
    logScript(obj); 
 
    var done = false; 
    // Attach handlers for all browsers 
    script.onload = script.onreadystatechange = function() { 
      loading--; 
      script.loaded = true; 
      if ( !done && (!this.readyState || 
          this.readyState === "loaded" || this.readyState === "complete") ) { 
        done = true; 
        script.onload = script.onreadystatechange = null; 
        debug("onload " + obj.src, obj); 
        flush(obj); 
      } 
    }; 
 
    script.loaded = false; 
    script.src = obj.src; 
    obj.depth++; 
 
    // Use insertBefore instead of appendChild to circumvent an IE6 bug. 
    // This arises when a base node is used (#2709 and #4378). 
    head.insertBefore( script, head.firstChild ); 
    setTimeout(function() { 
      if(!script.loaded) { throw new Error("SCRIPT NOT LOADED: " + script.src); } 
    }, obj.timeout); 
  } 
 
  function logScript (obj, code, lang) { 
    debug((code &#63; 
      "Inline " + lang + ": " + code.replace("\n", " ").substr(0, 30) + "..." : 
      "Inject " + obj.src), obj); 
  } 
 
  function separateScriptsFromHtml (htmlStr) { 
    return split(htmlStr, splitScriptsRegex); 
  } 
 
  function split (str, regexp) { 
    var match, prevIndex=0, tmp, result = [], i, l; 
 
    if(support.splitWithCapturingParentheses) { 
      tmp = str.split(regexp); 
    } else { 
      // Cross browser split technique from Steven Levithan 
      // http://blog.stevenlevithan.com/archives/cross-browser-split 
      tmp = []; 
      while(match = regexp.exec(str)) { 
        if(match.index > prevIndex) { 
          result.push(str.slice(prevIndex, match.index)); 
        } 
 
        if(match.length > 1 && match.index < str.length) { 
          Array.prototype.push.apply(tmp, match.slice(1)); 
        } 
 
        prevIndex = regexp.lastIndex; 
      } 
 
      if(prevIndex < str.length) { 
        tmp.push(str.slice(prevIndex)); 
      } 
 
    } 
 
    for(i=0, l=tmp.length; i<l; i=i+1) { 
      if(tmp[i]!=="") { result.push(tmp[i]); } 
    } 
    return result; 
  } 
 
  function stripNoScript (html) { 
    return html.replace(/<noscript>[\s\S]*&#63;<\/noscript>/ig, ""); 
  } 
 
  function trim (str) { 
    if(!str) { return str; } 
    return str.replace(/^\s*|\s*$/gi, ""); 
  } 
 
  function writeHtml (html, obj) { 
    if( isScript(html) ) { 
      var dummy = document.createElement("div"); 
      dummy.innerHTML = "dummy<div>" + html + "</div>"; // trick for IE 
      var script = dummy.children[0].children[0]; 
      var lang = script.getAttribute("language") || "javascript"; 
      if(script.src) { 
        obj.src = script.src; 
        obj.charset = script.charset; 
        obj.language = lang; 
        obj.type = script.type; 
        loadScript(obj); 
      } else { 
        var code = trim( script.text ); 
        if(code) { 
          logScript( obj, code, lang); 
          globalEval( code, lang); 
        } 
        flush(obj); 
      } 
    } else { 
      var container = getCachedElById(obj.domId); 
      if(!container) { 
        throw new Error("crapLoader: Unable to inject html. Element with id '" + obj.domId + "' does not exist"); 
      } 
       
      html = trim(html); // newline before <object> cause weird effects in IE 
      if(html) { 
        container.innerHTML += html; 
      } 
      checkWriteBuffer(obj); 
    } 
  } 
 
  function writeReplacement (str) { 
    inputBuffer.push(str); 
    debug("write: " + str); 
  } 
 
  function openReplacement () { 
    // document.open() just returns the document when called from a blocking script: 
    // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-open 
    return document; 
  } 
 
  function closeReplacement () { 
    // document.close() does nothing when called from a blocking script: 
    // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-close 
  } 
 
  publ = { 
    hijack: function(options) { 
      if(isHijacked) { return; } 
      isHijacked = true; 
      extend(globalOptions, options); 
      if(globalOptions.parallel && !support.scriptOnloadTriggeredAccurately) { 
        globalOptions.parallel = false; 
        debug("Browsers onload is not reliable. Disabling parallel loading."); 
      } 
 
      document.write = document.writeln = writeReplacement; 
      document.open = openReplacement; 
      document.close = closeReplacement; 
      document.getElementById = getElementByIdReplacement; 
    }, 
 
    release: function() { 
      if(!isHijacked) { return; } 
      isHijacked = false; 
      document.write = this.orgWrite; 
      document.writeln = this.orgWriteLn; 
      document.open = this.orgOpen; 
      document.close = this.orgClose; 
      document.getElementById = this.orgGetElementById; 
      elementCache = {}; 
    }, 
 
    handle: function(options) { 
      if(!isHijacked) { 
        debug("Not in hijacked mode. Auto-hijacking."); 
        this.hijack(); 
      } 
      var defaultOptsCopy = extend({}, defaultOptions); 
      var obj = extend(defaultOptsCopy, options); 
      obj.depth = 0; 
 
      if (!obj.domId) { 
        obj.domId = "craploader_" + new Date().getTime(); 
        var span = document.createElement("span"); 
        span.id = obj.domId; 
        document.body.appendChild(span); 
      } 
 
      if (options.func) { 
        runFunc(obj); 
        return; 
      } 
 
      if(globalOptions.parallel) { 
        setTimeout(function() { 
          loadScript(obj); 
        }, 1); 
      } else { 
        queue.push(obj); 
        setTimeout(function() { 
          if(loading === 0) { 
            checkQueue(); 
          } 
        }, 1); 
      } 
    }, 
 
    loadScript: function(src, domId, options) { 
      if (typeof domId !== "string") { 
        options = domId; 
        domId = undefined; 
      } 
      this.handle(extend({ 
        src:  src, 
        domId: domId 
      }, options)); 
    }, 
 
    runFunc: function(func, domId, options) { 
      if (typeof domId !== "string") { 
        options = domId; 
        domId = undefined; 
      } 
      this.handle( extend({ 
        domId: domId, 
        func:   func 
      }, options) ); 
    }, 
 
    orgGetElementById  : document.getElementById, 
    orgWrite      : document.write, 
    orgWriteLn     : document.writeln, 
    orgOpen       : document.open, 
    orgClose      : document.close, 
    _olt        : 1, 
    _oltCallback    : function() { 
      support.scriptOnloadTriggeredAccurately = (publ._olt===2); 
    } 
  }; 
 
  return publ; 
}());

로그인 후 복사

demo.php示例程序如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
 <head> 
 <meta http-equiv="content-type" content="text/html; charset=utf-8"> 
 <title> AD Loader </title> 
 <style type="text/css"> 
 .banner1{margin:10px; border:1px solid #CCCCCC; width:728px; height:90px;} 
 .banner2{margin:10px; border:1px solid #CCCCCC; width:300px; height:250px;} 
 </style> 
 <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script> 
 </head> 
 
 <body> 
 <div class="banner1" id="ad_728x90"></div> 
 <div class="banner2" id="ad_300x250"></div> 
 <div class="banner2" id="ad_l2_300x250"></div> 
   
 <&#63;php 
  function showAD($channel='', $step='', $async=''){ 
   include('ADLoader.class.php'); 
   $ad_config = include('ADConfig.php'); 
   ADLoader::setConfig($ad_config, 'ADLoader.js'); 
   return ADLoader::load($channel, $step, $async); 
  } 
 
  echo showAD('case_openx'); // 异步加载 
  //echo showAD('case_url');  // url方式异步加载 
  //echo showAD('case_sync_openx', 300, false); // 同步加载 
 &#63;> 
 
 </body> 
</html>

로그인 후 복사

adurl.php文件如下:

<&#63;php
$zoneid = isset($_GET['zoneid'])&#63; intval($_GET['zoneid']) : 0; 
if($zoneid){ 
&#63;> 
var zoneid = <&#63;=$zoneid &#63;>; 
var m3_u = (location.protocol=='https:'&#63;'https://ads.nmg.com.hk/www/delivery/ajs.php':'http://ads.nmg.com.hk/www/delivery/ajs.php'); 
var m3_r = Math.floor(Math.random()*99999999999); 
if (!document.MAX_used) document.MAX_used = ','; 
document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u); 
document.write ("&#63;zoneid=" + zoneid); 
document.write ('&cb=' + m3_r); 
if (document.MAX_used != ',') document.write ("&exclude=" + document.MAX_used); 
document.write (document.charset &#63; '&charset='+document.charset : (document.characterSet &#63; '&charset='+document.characterSet : '')); 
document.write ("&loc=" + escape(window.location)); 
if (document.referrer) document.write ("&referer=" + escape(document.referrer)); 
if (document.context) document.write ("&context=" + escape(document.context)); 
if (document.mmm_fo) document.write ("&mmm_fo=1"); 
document.write ("'><\/scr"+"ipt>"); 
<&#63; } &#63;>

로그인 후 복사

本文所述完整实例源码点击此处本站下载。

希望本文所述对大家的php程序设计有所帮助。

php中类的用法

class myclass
{
function showerror($msg)
{
$msg=trim($msg);
echo "

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/882892.htmlTechArticlephp广告加载类用法实例,php加载用法实例 本文实例讲述了php广告加载类的用法,非常实用。分享给大家供大家参考。具体方法如下: 该p...
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

<gum> : Bubble Gum Simulator Infinity- 로얄 키를 얻고 사용하는 방법
4 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
Nordhold : Fusion System, 설명
1 몇 달 전 By 尊渡假赌尊渡假赌尊渡假赌
Mandragora : 마녀 트리의 속삭임 - Grappling Hook 잠금 해제 방법
4 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

PHP와 Python : 다른 패러다임이 설명되었습니다 PHP와 Python : 다른 패러다임이 설명되었습니다 Apr 18, 2025 am 12:26 AM

PHP는 주로 절차 적 프로그래밍이지만 객체 지향 프로그래밍 (OOP)도 지원합니다. Python은 OOP, 기능 및 절차 프로그래밍을 포함한 다양한 패러다임을 지원합니다. PHP는 웹 개발에 적합하며 Python은 데이터 분석 및 기계 학습과 같은 다양한 응용 프로그램에 적합합니다.

PHP의 목적 : 동적 웹 사이트 구축 PHP의 목적 : 동적 웹 사이트 구축 Apr 15, 2025 am 12:18 AM

PHP는 동적 웹 사이트를 구축하는 데 사용되며 해당 핵심 기능에는 다음이 포함됩니다. 1. 데이터베이스와 연결하여 동적 컨텐츠를 생성하고 웹 페이지를 실시간으로 생성합니다. 2. 사용자 상호 작용 및 양식 제출을 처리하고 입력을 확인하고 작업에 응답합니다. 3. 개인화 된 경험을 제공하기 위해 세션 및 사용자 인증을 관리합니다. 4. 성능을 최적화하고 모범 사례를 따라 웹 사이트 효율성 및 보안을 개선하십시오.

PHP와 Python 중에서 선택 : 가이드 PHP와 Python 중에서 선택 : 가이드 Apr 18, 2025 am 12:24 AM

PHP는 웹 개발 및 빠른 프로토 타이핑에 적합하며 Python은 데이터 과학 및 기계 학습에 적합합니다. 1.PHP는 간단한 구문과 함께 동적 웹 개발에 사용되며 빠른 개발에 적합합니다. 2. Python은 간결한 구문을 가지고 있으며 여러 분야에 적합하며 강력한 라이브러리 생태계가 있습니다.

PHP와 Python : 그들의 역사에 깊은 다이빙 PHP와 Python : 그들의 역사에 깊은 다이빙 Apr 18, 2025 am 12:25 AM

PHP는 1994 년에 시작되었으며 Rasmuslerdorf에 의해 개발되었습니다. 원래 웹 사이트 방문자를 추적하는 데 사용되었으며 점차 서버 측 스크립팅 언어로 진화했으며 웹 개발에 널리 사용되었습니다. Python은 1980 년대 후반 Guidovan Rossum에 의해 개발되었으며 1991 년에 처음 출시되었습니다. 코드 가독성과 단순성을 강조하며 과학 컴퓨팅, 데이터 분석 및 기타 분야에 적합합니다.

PHP를 사용하는 이유는 무엇입니까? 설명 된 장점과 혜택 PHP를 사용하는 이유는 무엇입니까? 설명 된 장점과 혜택 Apr 16, 2025 am 12:16 AM

PHP의 핵심 이점에는 학습 용이성, 강력한 웹 개발 지원, 풍부한 라이브러리 및 프레임 워크, 고성능 및 확장 성, 크로스 플랫폼 호환성 및 비용 효율성이 포함됩니다. 1) 배우고 사용하기 쉽고 초보자에게 적합합니다. 2) 웹 서버와 우수한 통합 및 여러 데이터베이스를 지원합니다. 3) Laravel과 같은 강력한 프레임 워크가 있습니다. 4) 최적화를 통해 고성능을 달성 할 수 있습니다. 5) 여러 운영 체제 지원; 6) 개발 비용을 줄이기위한 오픈 소스.

PHP의 영향 : 웹 개발 및 그 이상 PHP의 영향 : 웹 개발 및 그 이상 Apr 18, 2025 am 12:10 AM

phphassignificallyimpactedwebdevelopmentandextendsbeyondit

PHP vs. Python : 사용 사례 및 응용 프로그램 PHP vs. Python : 사용 사례 및 응용 프로그램 Apr 17, 2025 am 12:23 AM

PHP는 웹 개발 및 컨텐츠 관리 시스템에 적합하며 Python은 데이터 과학, 기계 학습 및 자동화 스크립트에 적합합니다. 1.PHP는 빠르고 확장 가능한 웹 사이트 및 응용 프로그램을 구축하는 데 잘 작동하며 WordPress와 같은 CMS에서 일반적으로 사용됩니다. 2. Python은 Numpy 및 Tensorflow와 같은 풍부한 라이브러리를 통해 데이터 과학 및 기계 학습 분야에서 뛰어난 공연을했습니다.

PHP의 지속적인 사용 : 지구력의 이유 PHP의 지속적인 사용 : 지구력의 이유 Apr 19, 2025 am 12:23 AM

여전히 인기있는 것은 사용 편의성, 유연성 및 강력한 생태계입니다. 1) 사용 편의성과 간단한 구문은 초보자에게 첫 번째 선택입니다. 2) 웹 개발, HTTP 요청 및 데이터베이스와의 우수한 상호 작용과 밀접하게 통합되었습니다. 3) 거대한 생태계는 풍부한 도구와 라이브러리를 제공합니다. 4) 활성 커뮤니티와 오픈 소스 자연은 새로운 요구와 기술 동향에 맞게 조정됩니다.

See all articles