简体   繁体   English

在主文件中运行一段代码php文件

[英]run a section of code php file in main file

I'm very new to coding.I have a query related to open a php file in another file. 我对编码非常陌生。我有一个查询要在另一个文件中打开一个php文件。 I created a php file in the name "sidebarcolumn1.php" and following are the code in the file. 我创建了一个名为“ sidebarcolumn1.php”的php文件,以下是该文件中的代码。

<html>
<head>
</head>
<body>
<div id="sidecolumn1">
<div class="box_1b  box_x">
<div class="name_1 round_corner_top">New Categories:</a></div>
<ul class="list_2">
<li><a target="_self" href="/category/Site1/" title="Site1">Site1</a></li>
<li><a target="_self" href="/category/Site2/" title="Site2">Site2</a></li>
<li><a target="_self" href="/category/Site3/" title="Site3">Site3</a></li>
</ul><!--/list_1-->
<div class="slideDown">More [+]</div>
</div><!--/box_1b-->
</div>
</body>
</html>

Now I want to put it as a small section in main file (index.php) sidebar 现在,我要将其作为一小部分放在主文件(index.php)侧栏中

How should I call the file in the header? 我应该如何在标题中调用文件? How should I call it in a section within ? 我应该如何在其中的一个部分中称呼它? How to make it fully functional code for multiple pages (as it is going to remain common for all subpages)? 如何使其成为用于多个页面的全功能代码(因为它将在所有子页面中保持通用)?

要将子页面包含在主页中,请使用:

include('page_name.php');

You have two options: 您有两种选择:

  1. You can use the include 您可以使用include

    include('path.php'); include('path.php');

2.or the require 2.或require

require('path.php');

The difference is that, include (the page will run even if it cannot locates the file) while the require will make an error and will not run if it cannot locates the file 区别在于, include (页面即使无法找到文件也会运行),而require会出错并且如果找不到文件也不会运行。

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

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