2014-02-21 32 views
0

我有一個HTML表單,因爲這:查看源代碼,點擊一個按鈕

<Form Name ="form1" Method ="POST" ACTION = ""> 
Signore/a: 
<select name="sig"> 
<option value="1">Sig.re</option> 
<option value="2">Sig.ra</option> 
</select><br /><br /> 
Nome<input type="text" name="nome" maxlength="30" size="30"><br /><br /> 
arrivo: <br /> 
Giorno<input type="text" name="giornoa" maxlength="2" size="2">/ Mese 
<input type="text" name="mesea" maxlength="1" size="1"><br /><br /> 

在這種形式(即我沒有公開所有因爲太長),我有很多的PHP代碼對$ _POST變量做一個報價。最終的結果是一個變量,它是HTML和PHP這樣的組合:

echo $result="<table style='height: 48px; width: 571px;' border='1' bordercolor='#c0c0c0';> 
<tbody> 
    <tr> 
     <td style='text-align: center;'>$_POST['x1']</td> 
     <td style='text-align: center;'>$_POST['x2']</td> 
     <td style='text-align: center;'>$Total</td> 
</tr></tbody></table> "; 

通常由瀏覽器解釋輸出返回格式化文本。我喜歡在此窗體中添加一個按鈕,點擊該按鈕將返回源代碼"<html> <body> <table>...... </ table> </ body> </ HTML>",如在編寫文本和HTML源代碼時使用的在線程序(例如http://www.quackit.com/)。

回答

3

如果我理解正確的話,那麼使用可以使用highlight_file()highlight_string()

<?php 
if(isset($_POST['view_source'])) { 
    highlight_file($_SERVER['PHP_SELF']); // For the entire file 
    $code = "Your intended code here"; 
    highlight_string($code); // For the intended code 
} 
?><form method='post'> 
    <input type='submit' name='view_source' value='View Source' /> 
</form> 
+0

感謝一個TOT它的作品太好了!我可以添加一個PHP按鈕,在剪貼板中的ouptut複製? – user3318546

+0

我不明白爲什麼 – Magictallguy

+1

我會使用'highlight_file(__ FILE __);'而不是它,因爲它更常見。但是這也適用。 +1 –