如何在页面加载时使用一些PHP代码取代其他PHP代码

时间:2011-11-19 03:52:54

标签: php html load

我目前在页面/ div中有这个代码,当你加载它时没有任何东西在网址栏(a.k.a只是index.php)

<?php echo"<h1>For all of your Citation needs!</h1>

<div >

<p>

This page is for any citations you would need to make for reports or essays. Once you enter in the needed information for your sourse, it will spit out the citations in <a href='http://owl.english.purdue.edu/owl/resource/747/01/'>MLA</a> &amp; <a href='http://owl.english.purdue.edu/owl/resource/560/01/'>APA</a> format.</p>
<p >In development is a system where your citations are stored in a database and everytime you make a new one, you will be given related reference material to help your research. Also available soon will be the ability to look up references using related fields such as:</p>

<ul>
<li>Authors</li>
<li>Ttile of Work</li>
<li>Publishing Company</li>
<li>Journal Publisher</li>
<li>Academic Source</li>
<li>Something else will go here</li>
</ul>


</div>";  ?>

当我点击网站上的链接加载不同的表单数据(index.php?form = book)时,我希望表单数据取代已存在于该div中的内容。 。例如:

<?php
switch ($_GET['form'])
{
    case 'book':
        ?>
        <form method="POST" action="thispage.php">
            <input name="" type="text" value="fghfghfghfghfghfh" />
        </form>
        <?
        break;
    case 'b': // show form b
        ?>
        <form method="POST" action="thispage.php">
            <!-- form b elements here :) -->
        </form>
        <?
        break;
    case 'c': // show form c
        ?>
        <form method="POST" action="thispage.php">
            <!-- form c elements here :) -->
        </form>
        <?
        break;
}
?>

当你点击链接加载表单数据时,有没有办法让^ THIS ^ PHP代码块取代其他的php代码块?

1 个答案:

答案 0 :(得分:0)

将第一个“代码”块添加为switch语句的default。有更好的方法来构建您的页面,但是......

switch的PHP手册:http://php.net/manual/en/control-structures.switch.php

编辑:您的代码示例,已更新:

<?php
    switch ($_GET['form'])
    {
        case 'book':
            ?>
            <form method="POST" action="thispage.php">
                <input name="" type="text" value="fghfghfghfghfghfh" />
            </form>
            <?
            break;
        case 'b': // show form b
            ?>
            <form method="POST" action="thispage.php">
                <!-- form b elements here :) -->
            </form>
            <?
            break;
        case 'c': // show form c
            ?>
            <form method="POST" action="thispage.php">
                <!-- form c elements here :) -->
            </form>
            <?
            break;
        default:
            echo "<h1>For all of your Citation needs!</h1>

                <div >

                <p>

                This page is for any citations you would need to make for reports or essays. Once you enter in the needed information for your sourse, it will spit out the citations in <a href='http://owl.english.purdue.edu/owl/resource/747/01/'>MLA</a> &amp; <a href='http://owl.english.purdue.edu/owl/resource/560/01/'>APA</a> format.</p>
                <p >In development is a system where your citations are stored in a database and everytime you make a new one, you will be given related reference material to help your research. Also available soon will be the ability to look up references using related fields such as:</p>

                <ul>
                <li>Authors</li>
                <li>Ttile of Work</li>
                <li>Publishing Company</li>
                <li>Journal Publisher</li>
                <li>Academic Source</li>
                <li>Something else will go here</li>
                </ul>


                </div>";
                break;
    }
?>