If you include a php file, it will often fail. what do you need to pay attention?

Source: Internet
Author: User
If you include a php file, it will often fail. what do you need to pay attention? The online saying is related to the starting Terminator of php .
Let's talk about several situations,
Included php,
1. Before html
2. Only script
3. Html

In the main file,
1. php is used before and after include.
2. Before include, php is used.
3. include is followed by php
4. html before and after include
5. Before include, html
6. include is followed by html


Reply to discussion (solution)

This post was last edited by xuzuning at 09:21:23

Include a php file, which often fails.
The reason is that the path is incorrect and it has nothing to do with the writing of the master file and the sub-file (of course, the two files must be correct)

For example
B. php
   

A. php


When a. php is executed, only the following code is executed:


Echo 123;
?>
Echo 'ABCD ';
?>

Okay, add a prerequisite. the reference path is correct and the referenced php file has no syntax error.

Is the moderator's example incorrect? What do you mean?

If an error occurs, an error message is displayed!
No code or error information is available, and errors cannot be found.

There is no problem with my example. The purpose is to let you understand what the include is.

Your" ] "Is a short label, which is recommended for compatibility

We recommend that you add the php suffix because the default php suffix of the server is disabled. it is best to replace it with include_once.

Please refer to my questions and give me comments based on several situations.

Please refer to my questions and give me comments based on several situations.
None of your situations...

The failure to include a file is irrelevant to the source code of the file where the include is located, and is related to the file to be included.

When a file is contained, the parser disconnects the target file from the PHP mode to the HTML mode and restores it to the end of the file. For this reason, any code in the target file that needs to be executed as PHP code must be included in the valid PHP start and end tags.

Self-built http://cn2.php.net/manual/zh/function.include.php

The other is the include path. if the path is incorrect, it will fail.

Ensure that the encoding is consistent. gbk and UTF-8

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.