W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
{fetch}
用于獲取文件內(nèi)容、HTTP或者FTP內(nèi)容,以便輸出。
如果提供的文件名是以http://
開頭,那么網(wǎng)站的內(nèi)容將被獲取并顯示。
該函數(shù)不支持直接的HTTP訪問,請確認(rèn)網(wǎng)頁的地址是以斜杠結(jié)尾。
如果文件名是以ftp://
開頭,那么文件會被從FTP中下載并顯示。
本地文件而言,可以使用絕對路徑的文件,或者相對于當(dāng)前執(zhí)行的PHP腳本的路徑文件均可。
如果開啟了安全機制,那么從本地獲取文件內(nèi)容,{fetch}
函數(shù)僅能讀取在 $secure_dir
安全目錄下的文件。 參見安全機制。
如果你提供了assign
屬性, {fetch}
函數(shù)的輸出將不會顯示,而是賦值給模板變量。
參數(shù)名稱 | 類型 | 必選參數(shù) | 默認(rèn)值 | 說明 |
---|---|---|---|---|
file | string | Yes | n/a | 獲取的文件名、HTTP或者FTP網(wǎng)址 |
assign | string | No | n/a | 用于賦值的變量名 |
Example 8.5. {fetch} 例子
{* include some javascript in your template *} {fetch file='/export/httpd/www.example.com/docs/navbar.js'} {* embed some weather text in your template from another web site *} {fetch file='http://www.myweather.com/68502/'} {* fetch a news headline file via ftp *} {fetch file='ftp://user:password@ftp.example.com/path/to/currentheadlines.txt'} {* as above but with variables *} {fetch file="ftp://`$user`:`$password`@`$server`/`$path`"} {* assign the fetched contents to a template variable *} {fetch file='http://www.myweather.com/68502/' assign='weather'} {if $weather ne ''} <div id="weather">{$weather}</div> {/if}
參見 {capture}
, {eval}
, {assign}
和 fetch()
.
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: