Reasons for blank pages in PHP and how to solve them summary _php tips

Source: Internet
Author: User
Tags php programming blank page

Many programmers in the development of PHP have encountered a blank page, comprehensive analysis, in PHP programming in the presence of blank pages may be caused by the following several reasons:

1. Logic Error

Logic errors are the hardest to rule out, and on the face of it, maybe the code is legal, formal, but not predictable. Why, then? Perhaps the writer is not comprehensive enough, after all, people are people, computers are computers, computers can not be completely according to People's thinking to run the script. Here, I tell you a better debugging method is to use the annotation symbol "* * *", comment out some code, observe the operation, in order to eliminate the error, and finally find the location of the error code. In this case to completely eliminate logic errors, no patience is not, so to calm down, do not worry.

2, the behavior is not defined

Look at the following code:

<?php
$action = $_get[' id '];
if ($action = = ")
$action = 1;
if ($action = = 1) {
echo ("/$action ' s value is 1");
} else if ($action = = 2) {
echo ("/$action ' s value is 2"); 
   }
?>

This code is very clear, that is, if the $action variable is empty, set it to 1, and then judge the value of the $action variable to make a different event. Of course, if $action is neither equal to 1 nor equal to 2, what does PHP do? The answer is--nothing is going to happen, so there's a blank page. Knowing the reason, the solution is easy. The solution to this problem, very simple, in the If module after adding an else can be, print some information.

3. Grammatical errors

You may ask, if there is a grammatical error, the general will have the wrong hint, how can it be blank? Of course, this is only a few individual phenomena, in some home space, if you write PHP syntax errors, it will not have any hint. The solution is also very easy, before uploading the file in the local test, find the wrong code to correct.

4, misuse of the error screen character @

The error suppressor "@" is often used in places where errors can occur, but the use of a suppressor is too much or is not a good time, and can also cause white space to avoid it, to see the following two PHP scripts:

test1.php:

<?php
@include ("test2.php");
Echo ($var);
? >

test2.php:

<?php
$var = "Hi"//This line of code has errors, no semicolon
$var 1 = "Hello"//Ibid.
?>

Run the test1 to see, the result produces the blank page. Correcting is also very simple, you can remove the suppressors in front of the include function, or correct the errors in the test2.php file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.