PHP包括html选项

时间:2014-08-27 11:09:53

标签: php html include

我需要包含html,而不是文件,只需要简单的代码。 我的主要内容包括:

<?php
$content = array(
    '001'=>'content/001_001.php',
    '002'=>'content/001_002.php',
    '003'=>'content/001_003.php'
);
if(in_array($_GET['show'], array_keys($content))) {
    include($content[$_GET['show']]);
} else {
    include('content/001_001.php');
}
?>

另一方面,我想要包含简单的html,但这更像是每个类别中的3个按钮,所以克隆了很多* .html&amp; * .php文件不会是正确而干净的工作。

如果是打开的网页:?show=001,则会添加<div>001</div>; ?show=002,在一边将添加<div>002</div>等等。

1 个答案:

答案 0 :(得分:1)

如果我正确理解您的问题,您希望从数组而不是从文件加载HTML代码。您可以将包含更改为回显

<?php
    $content = array(
        '001'=>'<div><a href="#">001</a></div>',
        '002'=>'<div>002</div>',
        '003'=>'<div>003</div>'
    );
    if(!empty($_GET['show']) && isset($content[$_GET['show']])) {
        echo $content[$_GET['show']];
    } else {
        echo $content['001'];
    }
?>