English 中文(简体)
a <div>中对应的PHP和超文本。
原标题:Load PHP and HTML code to a PHP variable echoed in a <div>

我就是这种情况。 我有以下文字:

<?php
// ... other code ...
switch($_GET[ request ])    {
        case "firstPage":
            $file = APP_ROOT. "pages/firstPage.php";
            $hndle = fopen($file,"r");
            $right_column = fread($hndle, filesize($file));
            fclose($hndle);
            break;
        case "secondPage":
            $file = APP_ROOT. "pages/secondPage.php";
            $hndle = fopen($file,"r");
            $right_column = fread($hndle, filesize($file));
            fclose($hndle);
            break;
    }
}
?>
<div id="right_column">
    <?php echo $right_column;?>
</div>
// ... other code ...

取决于_GET[请求]美元的价值 我分配到可变的美元右线,以配合一个营地档案的内容。 然后,我重复了上半部分的变量。 The firstPage.php and secondPage. php的档案中含有混合的html和《实验室法》。 我寻求解决办法,如泽德的局部解决办法。 增 编

最佳回答

如果你确定一个变量,表明哪一种PHP文件包含,然后而不是阅读档案,那么这很可能更简单。 例如:

<?php
// ... other code ...
switch($_GET[ request ])    {
        case "firstPage":
            $file = APP_ROOT. "pages/firstPage.php";
            break;
        case "secondPage":
            $file = APP_ROOT. "pages/secondPage.php";
            break;
    }
}
?>
<div id="right_column">
    <?php include($file);?>
</div>
// ... other code ...

如果是第一Page.php和第二Page。 php的档案只有超文本,你重新做些什么会奏效。 如果有PHP,则需要include();或者你可以eval(<>>>/code>,但这又比你需要做更多的工作。

问题回答

First of all , your code is horrible, it should be something like :

$pages = array(
    firstPage    =>  pages/firstPage.php ,
    secondPage   =>  pages/secondPage.php 
);

$request =  firstPage ;
if ( array_key_exits($_GET,  request ) 
 &&  array_key_exists($pages, $_GET[ request ]) )
{
   $request = $_GET[ request ];
}
?>
<div id="right_column">
    <?php include  APP_ROOT . $pages[ $request ]; ?>
</div>

http://codeangel.org/articles/simple-php-template-engine.html 您可能会发现这一点。 它应当向你们解释,你如何能够轻易地利用加拿大本土的排位能力。

实际上,阅读和丢弃你的档案不是解决办法。 你只是向最终用户展示守则。

你们需要的是平价房价文档并显示结果。 您可以采取两种方式:

第一, in

 $file = APP_ROOT. "pages/firstPage.php";
 $hndle = fopen($file,"r");
 $right_column = fread($hndle, filesize($file));
 fclose($hndle);

你可以做到:

$right_column = include(APP_ROOT . "pages/firstPage.php");

因此,您的先辈。 格林纳达必须重新加入法典。 与此类似:

// firstPage.php
return "my html";

但是,你也可以把这一点纳入其中:

<div id="right_column">
    <?php include(APP_ROOT . "pages/firstPage.php"); ?>
</div>

Or, you can use the ob_get_contents. PHP has a nice documentation about how to use it.

我将发言。

在我看来,你可以通过公约进行规划,而不是发表越来越多的开关声明:

<?php
// ... other code ...

$file =   ;
if (isset($_GET[ request ])) {
    $safeFileName = sanitizeRequestForFileName($_GET[ request ]);
    $file = APP_ROOT.  pages/  . $safeFileName .  .php ;
}
?>
<div id="right_column">
    <?php 
        if (file_exists($file)) {
            include($file);
        }
    ?>
</div>
// ... other code ...




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!