Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP代码在浏览器中显示_Php_Browser - Fatal编程技术网

PHP代码在浏览器中显示

PHP代码在浏览器中显示,php,browser,Php,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

我在我的.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文件中。

您可以使两个文件保持不同。 对于smarty,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);
 ?>
确保.tpl页面上的表单发布在同一个php文件上

它将打印您的阵列

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

在.htaccess文件中

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

注意,这会像解析php一样解析所有tpl文件。模板引擎可能更好

我可能错了,但是如果你将一个PHP文件包含在一个tpl文件中,那么PHP将不会执行,但是将一个tpl文件包含在一个PHP文件中会起作用。你如何包含这个PHP?您使用的是哪种模板引擎?是否要解释tpl?如果然后检查它可能是逃逸thoseBy的方式,PHP应该放在您的控制器,如果您使用的是MVC框架。无需尝试将其包含在模板中。实际上是PHP“加载”了您的模板。不是相反我用的是smarty。。。。卡尔的评论确实有用,但并没有提供解决方案。
AddType application/x-httpd-php .php .html .tpl