PHP read local php File source code output display

Source: Internet
Author: User
Tags php file

If I have two files a.php,b.php.

The statements in the a.php file are:

The code is as follows Copy Code

<?php
echo "I am a.php";
?>

Now, I need to display the source code in the file a.php in the b.php file, which is the source code, as follows:

The code is as follows Copy Code

<?php
$a _code = file_get_contents (' a.php ');
Echo htmlspecialchars ($a _code);//www.111cn.net
?>

The emphasis is on this htmlspecialchars () function, where the Htmlspecialchars () function converts some predefined characters into HTML entities.


Look at one more instance fopen () function

The code is as follows Copy Code

$file = fopen ("a.php", "R");

The effect is the same as the above, of course, if we just want to display b.php in a.php, we can use INLUCDE () call directly

The code is as follows Copy Code
INLUCDE (' a.php ');

Can

If you want to read the. php file for the remote server, then the HTML content is returned, so don't ask why otherwise everyone will not write the program.

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.