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文件首先执行进程数据,然后在分配函数的帮助下,您可以将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

  2. 将lead_array替换为要用来访问 .tpl 文件中数组的名称

现在在 .tpl 页面上,您可以简单地编写

{$lead_array|print_r}

确保 .tpl 页面上的表单发布在同一个 PHP 文件上

它将打印您的数组

这是一个确定的解决方案,尝试一次,您将获得所需的输出。

.htaccess 文件中

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

请注意,这会解析所有 tpl 文件,就好像它们是 PHP 一样。模板引擎可能更好