本文目錄一覽:
- 1、html調用php
- 2、html中插入php的方法
- 3、html中使用php 的變量
- 4、html怎麼調用php返回的值並顯示出來。求代碼!
- 5、html網頁怎麼調用php文件
- 6、html 中 調用PHP代碼.
html調用php
你使用.php文件,但裏面可以寫html代碼,這是第一種方式。第二種可以設置php解析器解析html文件將裏面的php代碼解析
第一種:創建文件:abc.php
寫代碼:
!doctype html
html
bodyinput type=”hidden” name=”bianhao” value=”?php echo $_GET[“act”];?” //body
/html
html中插入php的方法
1、第一種是在HTML中加PHP。
head
meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ /
meta http-equiv=”Content-Language” content=”zh-CN” /
titleHello World/title
/head
body
?php
echo “Hello world!這是正文”;
?
/body
/html
2、第二種用echo輸出HTML。
因為HTML有的元素中有雙引號,所以用echo輸出的內容用單引號括起來,避免出錯,也省了轉義這一步。比如這樣的代碼:
?php
if(!$_POST){
echo 『form action=”” method=”post”
服務器地址:input type=”text” name=”host” value=”localhost” /br /
數據庫賬號:input type=”text” name=”user” value=”” /br /
數據庫密碼:input type=”password” name=”pwd” value=”” /br /
指定數據庫:input type=”text” name=”db” value=”test” /br /
input type=”submit” value=”確定”/
/form『;
}
?
3、第三種就是用()標記符了,這是在PHP168的模板代碼中首次見到的。
?php
print EOT
div class=”slidecont”{$label[deepblue_mainslide]}/div
div class=”newcontainter”
div class=”head”{$label[deepblue_mainh1]}/div
div class=”cont” id=”Tab1″{$label[deepblue_maint1]}/div
div class=”cont” id=”Tab2″{$label[deepblue_maint2]}/div
/div
a href=”$rs[url]” title=”$rs[descrip]” target=”_blank”$rs[name]/a
EOT;
?
html中使用php 的變量
html標籤使用php中的變量方法如下:
一、如果html標籤中使用php變量,提示:Undefined index: uid in /var/www//list.php ,list.php的具體代碼如下:
?php
require ‘redis.php’;
for ($i=0; $i = ($redis-get(“userid”)) ; $i++){
$data[] = $redis-hgetall(“user:”.$i);
}
/* var_dump($data) 的結果如下:
array (size=3)
0 =
array (size=0)
empty
1 =
array (size=4)
‘uid’ = string ‘1’ (length=1)
‘username’ = string ‘jjj’ (length=3)
‘password’ = string ‘123’ (length=3)
‘age’ = string ’20’ (length=2)
2 =
array (size=4)
‘uid’ = string ‘2’ (length=1)
‘username’ = string ‘lamp’ (length=4)
‘password’ = string ‘123’ (length=3)
‘age’ = string ’20’ (length=2)
*/
?
table border=”1″
captionuser list/caption
tr
thuid/th
thusername/th
thage/th
/tr
?php foreach ($data as $v) {?
tr
td?php echo $v[‘uid’] ?/td
td?php echo $v[‘username’] ?/td
td?php echo $v[‘age’] ?/td
/tr
?php } ?
/table
這時在echo 前 isset 下就可以了,代碼如下:
?php $a = 10; if( isset($a) ) { echo”這個變量存在”; } else{echo”這個變量不存在”; }?
二、 php 可以和html混編的 ,如下圖所示
html怎麼調用php返回的值並顯示出來。求代碼!
你最後一句「echo json_encode($info,320);」已經輸出這個結果了啊。
如果你是在html中直接用,就直接用就行了,如:p?php echo $info[‘name’]; ?/p;
如果你是在ajax中用,就直接在success方法里輸出就行了,如:
$.ajax({url:”xxx.php”,success:function(result){
console.log(result.name); }
});
html網頁怎麼調用php文件
HTML網頁是不支持直接寫入或者調用PHP語言的。。
PHP是服務器端解析的語言,HTML是瀏覽器端解析的語言。。
但是PHP文件里百分百支持HTML語言,如果非要PHP和HTML兼容的話,
用模板引擎吧,比如SMARTY。這裏面具體怎麼用一兩句話誰也不能講清楚,百度搜下SMARTY自學下原理吧。
html 中 調用PHP代碼.
首先,第一種寫法那是肯定錯誤的,php不能在?php?中再嵌套一個php標籤。第二種肯本沒看過的寫法,都拆的不成樣子了。第三種你到時候可以試試,或者麻煩點你可以先把$show_category_name;賦值給另一個名稱,然後
?php $show_name=$show_category_name;? value= “?php echo $lang[‘$show_name’];?”
原創文章,作者:LDEJZ,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/328920.html