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?
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With