簡體   English   中英

瀏覽器中顯示的PHP代碼

[英]PHP code showing in browser

我的.php文件中有一些PHP代碼,該代碼與瀏覽器中顯示的一樣。 與之類似,我希望代碼在表單提交時執行,但是它在瀏覽器中顯示為純文本。

<?php
 if(isset($_POST['ss-submit']))//submit button name
  {

 //Describing the Leads object and printing the array
 $describe = $connection->describeSObjects(array('Lead'));
 print_r($describe);
 ?>

它下面是可以正確顯示的HTML表單。

現在,此.php文件包含在.tpl文件中。

您可以使兩個文件保持不同。 如果是聰明人,首先執行php文件,然后處理過程數據,然后借助Assign函數,可以將php的輸出分配給tpl文件。

盡可能多地嘗試只在php頁面上處理數據

<?php
 if(isset($_POST['ss-submit']))//submit button name
  {
  //Describing the Leads object and printing the array
  $describe = $connection->describeSObjects(array('Lead'));
  $smarty->assign('lead_array',$describe);
 ?>
  1. 將$ smarty替換為您的smarty對象

  2. 將lead_array替換為您要訪問.tpl文件中的數組的名稱

現在在.tpl頁面上,您只需編寫

{$lead_array|print_r}

確保您在.tpl頁面上的表單發布在同一php文件上

它將打印您的數組

這是一個確定的解決方案,請嘗試一次,您將獲得所需的輸出。

在.htaccess文件中

AddType application/x-httpd-php .php .html .tpl

當心這將解析所有tpl文件,就好像它們是php一樣。 模板引擎可能更好

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM