2014-10-17 80 views
0

我想知道(所有的方式),PHP嵌入在HTML和HTML在PHP中。 我知道這個辦法:所有模式嵌入的PHP在HTML和HTML在PHP

<?php 
echo '<p>text here</p>'; 
?> 
<p>Some of this text is static, <?php echo 'text here'; ?></p> 

<?php echo '<p>'; ?> 
html text here... 
<?php echo '</p>';?> 

embedding in conditional 
<?php if(conditions) { ?> 
... HTML CODE ... 
<?php } ?> 

Embeding in ul 
<ul> 
<?php for($i=1;$i<=5;$i++){ ?> 
<li>Menu Item <?php echo $i; ?></li> 
<?php } ?> 
</ul> 

embeding in forms and textarea 

<form action = 「…..」 method = 「post」> 
Type your name:<br><input type = 「text」 name = 「name」 value = <?php code here...?>」<br> 
        <input type = 「submit」 value = 「submit」> 
</form> 
<textarea rows = 「7」 cols=」25」><?php cod here.... ?></textarea> 

請給我在PHP嵌入HTML和HTML嵌入php.It對我來說很重要的另一種模式!

+1

模板引擎是我能想到的唯一的其他方式.. SMARTY,Dwoo,Savant,Pear ..名單繼續.. – Pogrindis 2014-10-17 08:45:47

回答

1

這裏有兩種方法可以做到這一點。第一個在HTML中嵌入PHP:

<html> 
<title>HTML with PHP</title> 
<body> 
<h1>My Example</h1> 

<?php 
//your php code here 
?> 

<b>Here is some more HTML</b> 

<?php 
//more php code 
?> 


</body> 
</html> 

的,另外,嵌入HTML在PHP中,回聲:

<?php 
Echo "<html>"; 
Echo "<title>HTML with PHP</title>"; 
Echo "<b>My Example</b>"; 

//your php code here 

Print "<i>Print works too!</i>"; 
?> 

您可能會發現這個tutorialquestion有用。

希望它有幫助。

克萊門西奧莫拉萊斯盧卡斯。

+0

謝謝..我正在等待其他方式 – 2014-10-17 08:50:50

3

PHP不知道html。所有的PHP都知道是字符串。 PHP代碼可以嵌入文檔中的任何位置,使用<?= value ?><?php statements; ?>

+0

好..但期待除了我的其他例子 – 2014-10-17 08:57:34

+1

@DanutMarianGabrian你期待什麼黑魔法? – Pogrindis 2014-10-17 08:59:49

+0

男人,如果你不知道例子...讓別人。 Php不僅僅依靠單詞..是基於例子來理解..因爲我是乞丐 – 2014-10-17 09:10:37