How can i get the html tags and texts of a web page in php?

Well, like in python.... for example with a web crawler (with BeautifulSop if I'm correct) that we can get all html tags and text of a web page and then save it to a text file.

I want to do the same with php, give the url of a web page and receive it's html tags and contents.

Member Avatar

file_get_contents() will take the entire file. Alternatively use cURL?

Would you give me an example please?
An example that you give a url to the script, and it gets all the html tags and text of that page and echo it on a file. I want the output to have text and html tags together.

@TexWiller, file_get_html() didn't work for me because of the html word in it and had to replace it with the word contents to get a result.

and also with:

foreach($html->find('img') as $element)
       echo $element->src . '<br>';

foreach($html->find('a') as $element)
       echo $element->href . '<br>';

there was no result and nothing appeaed on the page. (for www.google.com).