Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get text from a website using PHP?

Tags:

php

web

So, I'm working on a PHP script, and part of it needs to be able to query a website, then get text from it.

First off, I need to be able to query a certain website URL, then I need to be able to get text from the text from that website after the query, and be able to return that text out of the function.

How would I query the website and get the text from it?

like image 768
Alper Avatar asked Jul 18 '11 03:07

Alper


1 Answers

The easiest way:

file_get_contents()

That will get you the source of the web page.

You probably want something a bit more complete though, so look into cURL, for better error handling, and setting user-agent, and what not.

From there, if you want the text only, you are going to have to parse the page. For that, see: How do you parse and process HTML/XML in PHP?

like image 86
Brad Avatar answered Oct 05 '22 10:10

Brad