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

Recommended Answers

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

Jump to Post

All 8 Replies

Re: how to get all html tags and texts of a web page in php 80 80
Member Avatar

Can you elaborate?
Why do you need this? Sounds a bit clunky to me. You can use DOMDocument to load a file: http://php.net/manual/en/domdocument.loadhtmlfile.php

Re: how to get all html tags and texts of a web page in php 80 80

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.

Re: how to get all html tags and texts of a web page in php 80 80
Member Avatar

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

Re: how to get all html tags and texts of a web page in php 80 80

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.

Re: how to get all html tags and texts of a web page in php 80 80

I found an example myself:

    $url = “http://www.howtogeek.com”;

    $str = file_get_contents($url);
Re: how to get all html tags and texts of a web page in php 80 80

Thank you @diafol.

Re: how to get all html tags and texts of a web page in php 80 80

my best choice is
Click Here
linear and well document also works well.

Re: how to get all html tags and texts of a web page in php 80 80

@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).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.