0

我有一个简单的 php 问题。我想包含一个简单的 PHP 文件。我include("filename.php") 用来包含文件。

但问题是,如果文件包含正常,那么它会显示错误,但如果包含的文件中有任何错误,那么它就会死掉并且没有进一步的执行。

我希望如果包含的文件中有任何错误,它只会显示错误并且应该继续进一步执行:

就像在包含文件之后一样,我正在显示footer. 目前,如果代码中有任何错误,则页脚不显示,如果我想在包含文件有错误时显示页脚。我怎样才能做到这一点 ?

编辑

<?php

include("header.php");
include("dbconnect.php");

<div class="content">
    <div class="container">
    <div >
    <form name="savecode" action="" method="post">
<div class="span12">

<form action="#" method="post">
<input type="hidden" name="language" value="PHP">
<textarea id="code" name="yourcode" style="width:800px;height:200px;"><?php echo $code;?></textarea>
<br/><input type="submit" class="btn btn-primary" name="reruncode" value ="Run the code">
</div>
<hr/>
<div class="span12">
<h5>Output of the above code</h5>

<textarea id="output" style="width:800px;height:200px;" disabled="disabled">
<?php

include("testfile.php");
?>
</textarea>
<?php
if(isset($_SESSION['email']))
{
$uniquid = md5(uniqid($email,true));
echo "<input type='hidden' id='uniqid' value=$uniquid>";
?>
<input type="hidden" id="email" value="<?php echo $_SESSION['email']; ?>">
<br/><input id="submit" value="Save this code" class="btn btn-primary" />
<?php
}
?>
</div>
</div>
</div>

</div>
</div>

include("footer.php");
4

2 回答 2

0

如果包含文件中存在解析错误,则这是不可能的,执行将终止。尝试捕获异常也不起作用。它在这里
进一步讨论 如果它是包含文件中的一般错误,请确保您尝试捕获包含文件中的所有可能异常,以便它正常失败,然后在这种情况下可以包含它。

于 2013-06-28T03:16:11.460 回答
-1

您需要将 HTML 放入字符串中或在 HTML 开始之前关闭 PHP 标记,并在 HTML 结束后再次启动 PHP 标记。

在您的代码中,您错过了它。另一个是带有表单元素的表单。发布数据时它将不起作用。您的 Form 标签在代码中的任何地方都没有关闭。

例如

<?php

include("header.php");
include("dbconnect.php");

?>

<div class="content">
    <div class="container">
        <div>
            <form name="savecode" action="" method="post">
               <div class="span12">

                   <form action="#" method="post">
                       <input type="hidden" name="language" value="PHP">
                       <textarea id="code" name="yourcode" style="width:800px;height:200px;"><?php echo $code;?></textarea>
                       <br/><input type="submit" class="btn btn-primary" name="reruncode" value ="Run the code">
               </div>
               <hr/>
               <div class="span12">
                    <h5>Output of the above code</h5>

                     <textarea id="output" style="width:800px;height:200px;" disabled="disabled">
                     <?php include("testfile.php"); ?>
                     </textarea>
                     <?php
                     if(isset($_SESSION['email']))
                     {
                         $uniquid = md5(uniqid($email,true));
                         echo "<input type='hidden' id='uniqid' value=$uniquid>";
                     ?>
                         <input type="hidden" id="email" value="<?php echo $_SESSION['email']; ?>">
                         <br/><input id="submit" value="Save this code" class="btn btn-primary" />
                     <?php
                     }
                     ?>
                </div>
           </div>
       </div>

    </div>
</div>

<?php include("footer.php"); ?>
于 2013-06-28T03:20:53.873 回答