How do I get text from a website using PHP?

后端 未结 7 2040
北海茫月
北海茫月 2020-12-31 11:33

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

7条回答
  •  抹茶落季
    2020-12-31 11:46

    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?

提交回复
热议问题