Hello

I want to extract content of a website found between some specific html tags.How can i achieve that with php.
For e.g consider viewing google.com soure code.I want to extract data with <title> </title> tags and store it in a variable(its "Google" in this case)

Bascially script navigates to google.com and then extract data within the <title> </title> tags. I though of using fopen and fread but this would take all webpage content and isn't efficient.

Any better solution

Recommended Answers

All 3 Replies

You'd need to download most of the content anyway, or in blocks, because you can't know where in the HTML the title is. If fopen is allowed, you can read a block, and then use a preg_xxx or XML function to get the title. If fopen isn't allowed, try cUrl. A working example can be found on StackOverflow already.

I know exact where is the title tag for the sites that i need.{i mean the line number}
Give me link for example
Greetz pritaeas

There is a php class called simple html DOM parser that can also help you achieved this task. For google, they have a custom search API, however this have a limit of 100 quieries per day and they want a fee of $5 per 1000 queries, for up to 10,000 queries per day.

commented: nice parser - thanks for sharing +14
Be a part of the DaniWeb community

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