Home  >  Article  >  Backend Development  >  PHP 完结脚本 但是不影响后面的HTML输出

PHP 完结脚本 但是不影响后面的HTML输出

WBOY
WBOYOriginal
2016-06-13 12:53:34789browse

PHP 结束脚本 但是不影响后面的HTML输出
可能是比较小白的问题。
比如:

<?php<br />
	if(!isset($_GET["id"])||!isset($_GET["code"]))<br />
	{<br />
		echo "<title>注册验证</title>";<br />
		exit();<br />
	}<br />
        else<br />
        {<br />
                echo "<title>注册验证1</title>";<br />
        }<br />
        ......<br />
?>


比如这段脚本在本身HTML中

的位置,判定是否有GET提交的数据来输出不同的title<br> 后面是有脚本的,但是如果GET没有数据传来,后面连接数据库什么的就没有必要,所以想要结束。<br> 但是结束后,使用exit或者return,后面HTML中的内容等也就不输出了,该怎么办?

------解决方案--------------------
不能 exit();
而应将连接数据库什么的放在 else 分支中
------解决方案--------------------
你也可以把这些php代码放在单独的文件中 include 进来
只是要将  exit(); 改为 return;

------解决方案--------------------
本帖最后由 xuzuning 于 2013-02-21 12:57:32 编辑 你还可以写成函数
作为结构化编程,无非就是
if else
if elseif else
switch case default
另类点就是
while break

真的不喜欢结构化编程时
php5.3已经恢复了对 goto 的支持,适当的使用也还是蛮不错的
goto a;<br />
echo 123; //这里不会被执行<br />
a:<br />
echo 'abcd';<br />
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn