有什么办法可以推迟 PHP 代码吗?
就像在 javascript 中我们使用<script defer="defer"></script>
. 有没有办法对 PHP 代码做同样的事情?
更新: 这是我使用的代码:
信息:此代码位于我的侧边栏中,并导致网站在加载时停止 2-3 秒。我正在尝试跳过此过程并在站点的其余部分已加载时加载此代码....我也愿意接受其他编码解决方案。
<div style="padding:5px;">
<?php
function currency($from_Currency,$to_Currency,$amount) {
$amount = urlencode($amount);
$from_Currency = urlencode($from_Currency);
$to_Currency = urlencode($to_Currency);
$url = "http://www.google.com/ig/calculator?hl=en&q=$amount$from_Currency=?$to_Currency";
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$rawdata = curl_exec($ch);
curl_close($ch);
$data = explode('"', $rawdata);
$data = explode('"', $data['3']);
$var = $data['0'];
return round($var,1);
}
?>
<div style="padding:2px; border-bottom:1px solid #EFEFEF;">1 USD er <?php echo currency("USD","NOK",1); ?> NOK<br />
</div>
<div style="padding:2px; border-bottom:1px solid #EFEFEF;">1 EUR er <?php echo currency("EUR","NOK",1); ?> NOK<br />
</div>
<div style="padding:2px; border-bottom:1px solid #EFEFEF;">1 GBP er <?php echo currency("GBP","NOK",1); ?> NOK<br />
</div>
<div style="padding:2px; border-bottom:1px solid #EFEFEF;">1 SEK er <?php echo currency("SEK","NOK",1); ?> NOK<br />
</div>
<div style="padding:2px; border-bottom:1px solid #EFEFEF;">1 DKK er <?php echo currency("DKK","NOK",1); ?> NOK<br />
</div>
</div>