本文目錄一覽:
- 1、如何在PHP中嵌入一個HTML文件
- 2、thinkphp中html頁面怎麼引入html頁面?
- 3、php插入html文件
- 4、php怎麼調用html
- 5、PHP代碼嵌入HTML網頁的方式是哪四種
- 6、thinkphp中html頁面怎麼引入html頁面
如何在PHP中嵌入一個HTML文件
php裏面添加html文件,很多時候需要用到!
如添加一個站點統計到網站,如果你的網站全部是php來寫的,這時候直接用echo輸出統計代碼就會出現問題!然後php可以很方便的引入一個html文件,這樣就方便多了!
具體操作如下:
在do_footer函數裏面利用include即可導入一個html文件
1)修改do_footer函數
function do_footer($credits = true) {
global $globals;
echo “/div!–#container closed–\n”;
include(“hugwww-footer.html”);
if($credits) @do_credits();
do_js_from_array($globals[‘post_js’]);
// warn warn warn
// dont do stats of password recovering pages
@include(『ads/stats.inc』);
printf(“\n!–Generated in %4.3f seconds–\n”, microtime(true) – $globals[‘start_time’]);
2)將統計代碼寫入hugwww-footer.html文件完成!
thinkphp中html頁面怎麼引入html頁面?
引入代碼如下:
1,主界面index.html
代碼:
標籤:
div id=”main”
/div
button id=”btn”點擊/button
js:
script
$(“#btn”).click(function() {
$.post(‘__URL__/show’, function(data) {
$(document).ready(function(){$(“#main”).html(data);})
});
});
/script
2,show.html網頁
div id=”div2″
h3aaaaaa/h3
h3aaaaaa/h3
h3aaaaaa/h3
h3aaaaaa/h3
h3aaaaaa/h3
/div
3, IndexAction.class.php
public function show(){$this-display();}
結果:
div id=”main”
div id=”div2″
h3aaaaaa/h3
h3aaaaaa/h3
h3aaaaaa/h3
h3aaaaaa/h3
h3aaaaaa/h3
/div
/div
button id=”btn”點擊/button
php插入html文件
PHP插入或者引入外部文件的函數有:require,require_once,include,include_once等;插入HTML文件使用其中任意一個函數都可以;
比如zhidao.php要插入zd.html文件,示例如下:
!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “”
html
head
meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″
titleHTML/title
/head
body
font color=”red”html部分/font
/body
/html
?php
echo “———–插入的HTML內容如下—————-“;
echo “br/”;
require ‘test.html’;
?
運行效果如下:
php怎麼調用html
html表單最基本的形式是form中設置action屬性(數據提交路徑)method表示提交數據的類型(get和post)。使用這種方式提交表單,表單元素必須設置name屬性。
表單中設置這兩個屬性就可以獲得表單的值了。
例如:
form
action=”index.php”
method=”post”
input
type=”text”
name=”user”
/
input
type=”submit”
value=”提交”
/
/form?php
//post接收表單傳過來的值
$user=$_POST[‘user’];
echo
$user;
?
PHP代碼嵌入HTML網頁的方式是哪四種
1.xml風格
?php
echo”這是xml風格的標記”;
?
xml風格的標記是常用的標記,也是推薦使用的標記,服務器不能禁用,該風格的標記在xml,xhtml中都可以使用。
2.腳本風格
script languange=”php”
echo’這是腳本風格的標記’;
/script
3.簡短風格
?這是簡短風格的標記;?
註:需要在 php.ini 配置文件中開啟 short_open_tag = on;
4.asp風格
%
echo’這是asp風格的標記’;
%
註:需要在 php.ini 配置文件中開啟 asp_tags = on;
上面asp風格與簡短風格需要在php.ini中設置下。默認是不支持的。
thinkphp中html頁面怎麼引入html頁面
8.7 包含文件
可以使用Include標籤來包含外部的模板文件,使用方法如下:
include標籤(包含外部模板文件)
閉合
閉合標籤
屬性
file(必須):要包含的模板文件,支持變量
示例:
1、 使用完整文件名包含
格式:include file=”完整模板文件名” /
例如:
include file=”./Tpl/default/Public/header.html” /
這種情況下,模板文件名必須包含後綴。使用完整文件名包含的時候,特別要注意文件包含指的是服務器端包含,而不是包含一個URL地址,也就是說file參數的寫法是服務器端的路徑,如果使用相對路徑的話,是基於項目的入口文件位置。
2、包含當前模塊的其他操作模板文件
格式:include file=”操作名” /
例如 導入當前模塊下面的read操作模版:
include file=”read” /
操作模板無需帶後綴。
3、 包含其他模塊的操作模板
格式:include file=”模塊名:操作名” /
例如,包含Public模塊的header操作模版:
include file=”Public:header” /
4、包含其他模板主題的模塊操作模板
格式:include file=”主題名:模塊名:操作名” /
例如,包含blue主題的User模塊的read操作模版:
include file=”blue:User:read” /
5、 用變量控制要導入的模版
格式:include file=”$變量名” /
例如
include file=”$tplName” /
給$tplName賦不同的值就可以包含不同的模板文件,變量的值的用法和上面的用法相同。
無論你使用什麼方式包含外部模板,Include標籤支持在包含文件的同時傳入參數,例如,下面的例子我們在包含header模板的時候傳入了title和keywords變量:
include file=”header” title=”ThinkPHP框架”keywords=”開源WEB開發框架”/
就可以在包含的header.html文件裏面使用var1和var2變量,方法
html xmlns=””
head
title[title]/title
meta name=”keywords” content=”[keywords]” /
/head
注意:由於模板解析的特點,從入口模板開始解析,如果外部模板有所更改,模板引擎並不會重新編譯模板,除非在調試模式下或者緩存已經過期。如果部署模式下修改了包含的外部模板文件後,需要把模塊的緩存目錄清空,否則無法生效。
原創文章,作者:NWRK,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/139288.html