Home  >  Article  >  Backend Development  >  PHP function that can obtain the HTML code of any web page

PHP function that can obtain the HTML code of any web page

WBOY
WBOYOriginal
2016-07-25 08:42:43911browse
  1. function display_sourcecode($url)
  2. {
  3. $lines = file($url);
  4. $output = "";
  5. foreach ($lines as $line_num => $line) {
  6. // loop thru each line and prepend line numbers
  7. $output.= "Line #{$line_num} : " . htmlspecialchars($line) . "
    n";
  8. }
  9. }
复制代码

用法:

  1. $url = "http://www.open-open.com";
  2. $source = display_sourcecode($url);
  3. echo $source;
  4. ?>
复制代码

Web, HTML, PHP


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