简体   繁体   English

浏览器中显示的PHP代码

[英]PHP code showing in browser

I have some PHP code in my .php file which is showing as it is in the browser. 我的.php文件中有一些PHP代码,该代码与浏览器中显示的一样。 As in, I want the code to execute on form submit, but its showing as plain text in the browser. 与之类似,我希望代码在表单提交时执行,但是它在浏览器中显示为纯文本。

<?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);
 ?>

Below it is an HTML form which displays correctly. 它下面是可以正确显示的HTML表单。

now this .php file is included in a .tpl file. 现在,此.php文件包含在.tpl文件中。

You can keep your both files different. 您可以使两个文件保持不同。 In case of smarty the php file is executed first process data and then with the help of assign function you can assign your output from php to the tpl file. 如果是聪明人,首先执行php文件,然后处理过程数据,然后借助Assign函数,可以将php的输出分配给tpl文件。

Try as much as you can process data at the php page only 尽可能多地尝试只在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. Replace $smarty with your smarty object 将$ smarty替换为您的smarty对象

  2. Replace lead_array with a name with which you want to access array in .tpl file 将lead_array替换为您要访问.tpl文件中的数组的名称

now on the .tpl page you can simply write 现在在.tpl页面上,您只需编写

{$lead_array|print_r}

make sure your form on the .tpl page post on the same php file 确保您在.tpl页面上的表单发布在同一php文件上

it will print your array 它将打印您的数组

This is a sure solution try it once and you will get desired output. 这是一个确定的解决方案,请尝试一次,您将获得所需的输出。

in a .htaccess file 在.htaccess文件中

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

beware this parses all tpl files as if they were php. 当心这将解析所有tpl文件,就好像它们是php一样。 A templating engine may be better 模板引擎可能更好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM