[英]How to run PHP coming from a separate file
I have a form thats action is another page. 我有一个表单,多数民众赞成在动作是另一页。
<form class="indexSearch" action="search.php" method="post">
to keep my code neat I'm keeping all my PHP code in a separate file that I am including in the head of every page... 为了使代码保持整洁,我将所有PHP代码都保存在一个单独的文件中,该文件包含在每个页面的开头...
<head>
<?php include 'include/includes.php';?>
</head>
The problem I'm having is when the PHP code in the includes.php
file runs, it echoes at the top left hand corner of the page I want it to appear on and I am confused about the best way to include it where I need it... 我遇到的问题是,
includes.php
文件中的PHP代码运行时,它在我希望它出现在页面的左上角回显,并且我对在需要的地方包括它的最佳方法感到困惑它...
Any help would be greatly appreciated. 任何帮助将不胜感激。
Thx 谢谢
Sorry just to update on my question which was a bit vague in the include file I intend to hold all functions / scripts etc... the particular code I am trying to output in this instance is a while loops from a mysqli query 对不起,我只是想更新我的问题,我打算保留所有函数/脚本等在包含文件中有点含糊...在这种情况下,我试图输出的特定代码是一个从mysqli查询中循环的循环
不用在include php中执行回显,而是分配给一个变量,然后使用以下命令将其回显到所需的位置:
<?php echo $varname; ?>
Put some conditions in your include.php
在
include.php
一些条件
you can use functions such as isset()
, empty()
to protect them to print that by default. 您可以使用
isset()
, empty()
来保护它们以默认情况下进行打印。
and my personal suggestion is that use require_once('include/include.php')
; 我的个人建议是使用
require_once('include/include.php')
;
<?php include 'include/includes.php'; ?>
In includes.php: define your values in to variable, 在includes.php中:将值定义为变量,
<?php $Variable = 'test check'; ?>
Now include your file where ever you want, after the inclusion of your includes.php
you can able to retrive and print the value of $Variable
. 现在,将文件包含在任何位置,在包含了
includes.php
您就可以检索并打印$Variable
的值了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.