Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get HTML source code of page with PHP

Tags:

html

php

If I have the html file:

<!doctype html>
 <html>
  <head></head>
   <body>
    <!-- Begin -->
    Important Information
    <!-- End -->
   </body>
  </head>
 </html>

How can I use PHP to get the string "Important Information" from the file?

like image 383
JJJollyjim Avatar asked Feb 16 '11 03:02

JJJollyjim


People also ask

How can I get source URL in PHP?

Append the HTTP_HOST(The host to which we have requested, e.g. www.google.com, www.yourdomain.com, etc…) name of the server. Append the REQUEST_URI(The resource which we have requested, e.g. /index. php, etc…) to the URL string.

Can PHP generate HTML code?

PHP and HTML interact a lot: PHP can generate HTML, and HTML can pass information to PHP. Before reading these faqs, it's important you learn how to retrieve variables from external sources. The manual page on this topic includes many examples as well.

Can I see PHP source code?

PHP is a server-side programming language, meaning it is executed at the web server before the website is sent to the end-user. This is why you can't see the PHP code when you view the source code.

How do I get the source code from HTML?

To view only the source code, press Ctrl + U on your computer's keyboard. Right-click a blank part of the web page and select View source from the pop-up menu that appears.


1 Answers

If you already have the parsing sorted, just use file_get_contents(). You can pass it a URL and it will return the content found at the URL, in this case, the html. Or if you have the file locally, you pass it the file path.

like image 53
Endophage Avatar answered Sep 25 '22 01:09

Endophage