Home  >  Article  >  Backend Development  >  How to output html source code in php

How to output html source code in php

藏色散人
藏色散人Original
2018-12-22 15:43:0222407browse


php outputs html source code, which can be achieved through the htmlspecialchars function. htmlspecialchars means converting special characters into HTML entities.

How to output html source code in php

# Below we will combine specific code examples to introduce how PHP outputs the html source code of a specified page.

The code example is as follows:

<?php
$all_lines = file(&#39;http://www.php.cn/&#39;);
foreach ($all_lines as $line_num => $line)
{
    echo "第{$line_num}行: " . htmlspecialchars($line) . "<br>";
}

In the above code, we read the content of "http://www.php.cn/" into the array through the file function for the first time, and each element of the array Corresponding to a line in the file, newlines are still appended. On failure, file() returns FALSE. Then iterate through the content of each line through a foreach loop and use the htmlspecialchars function to convert the special characters into HTML entities.

Then the source code of the page "http://www.php.cn/" is finally output. Some screenshots are as follows:

How to output html source code in php

Note:

Source code is the source of a computer program. It contains declarations, instructions, functions, loops, and other statements that act as instructions for the program on how to run. A program may contain one or more source code text files, which may be stored on your computer's hard drive, in a database, or printed in code snippets.

Programmers can add comments to their source code to help other developers understand it. It is also possible to run short scripts from source code using a scripting engine such as a VBScript or PHP engine.

While large programs often reference hundreds or thousands of files, it is not uncommon for small programs to use only one source code. If there are many source files, the program can be organized into different parts. If a single file contains all of a program's variables and functions, it can be difficult to find specific parts of the code.

This article is about the method of php outputting html source code. It is also very simple. I hope it will be helpful to friends in need!


The above is the detailed content of How to output html source code in php. For more information, please follow other related articles on the PHP Chinese website!

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