【问题标题】:How to run a PHP file from other PHP file?如何从其他 PHP 文件运行 PHP 文件?
【发布时间】:2013-04-16 11:07:21
【问题描述】:

我有一个 PHP 文件,它自己可以正常工作,但我需要它在我主页的某个名为 file.php 的部分上运行。

我希望 myfile.php 在 file.php 中运行,我在需要它的地方正确 div 容器并尝试了 <?php include("myfile.php"); ?> 它可以工作,但我想要它的自动大小。

假设 myfile.php 的表格宽度大小为 900px,但是当我打开 file.php 时,myfile.php 中的表格大小变小了。尺寸变为低于 900 像素。如何在 myfile.php 中使用 div 容器在 file.php 中运行的那个表仍然是 900px?

【问题讨论】:

  • 你说的是...include? ...iframe? ...div 风格overlay?
  • @Welly: < 符号被解释为标记的一部分。您可能希望在反引号之间转义它们或您的代码行。您问题的其他部分不可见。
  • 请出示您的代码

标签: php html containers


【解决方案1】:

你可以使用 php "include"

<div id="container">
<?php include("myfile.php"); ?>
</div>

顺便说一句,你想用尺寸做什么,我相信你需要 CSS 来做到这一点,而不是 php。

也许这样

我的文件.php

<table style="width:900px">
<tr><td></td></tr>
</table>

【讨论】:

    【解决方案2】:

    在文件.php中

    include "path/to/myfile.php";

    【讨论】:

      【解决方案3】:

      这段代码index3.php带div

      <!DOCTYPE html
         PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
      
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      <title>JS Change Class</title>
      <script language="JavaScript" src="js/adspreview.js"type="text/javascript" xml:space="preserve"></script>
      
      <div id="container">
              <td><?php include("test.php"); ?>
      </div>
      </html>
      

      这里是我想在 index3.php 中运行的代码

      <html>
      
      <head>
      <meta http-equiv="Content-Language" content="en-us">
      <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
      <title>Test</title>
      </head>
      
      <body>
      
      <table border="1" width="100%">
          <tr>
              <td bgcolor="#0000FF" colspan="2">
              <p align="center"><font color="#FFFFFF" face="Arial"><b>Test</b></font></td>
          </tr>
          <tr>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
          </tr>
      </table>
      
      </body>
      
      </html>
      

      请尝试一下,我对此感到困惑。感谢您的帮助。

      【讨论】:

        【解决方案4】:

        首先: index3.php

        <!DOCTYPE html
           PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
           "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
        
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>JS Change Class</title>
        <script language="JavaScript" src="js/adspreview.js"type="text/javascript" xml:space="preserve"></script>
        </head>
        <body>
        <div id="container">
                <?php include("test.php"); ?>
        </div>
        </body>
        </html>
        

        第二: teste.php

        <table border="1" width="100%">
            <tr>
            <td bgcolor="#0000FF" colspan="2">
                <p align="center"><font color="#FFFFFF" face="Arial"><b>Test</b></font>
            </td>
            </tr>
            <tr>
                <td>&nbsp;</td>
            </tr>
        </table>
        

        CTRL+C + CTRL+V ^^

        【讨论】:

          猜你喜欢
          • 2012-09-05
          • 2019-12-29
          • 2015-03-04
          • 2010-10-24
          • 1970-01-01
          • 2015-07-09
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多