PHP extract article excerpt from a page

后端 未结 2 1893
醉酒成梦
醉酒成梦 2021-01-19 11:10

anyone have any idea how to generate excerpt from any given article page (so could source from many type of sites)? Something like what facebook does when you paste a url in

相关标签:
2条回答
  • 2021-01-19 11:23

    Here is a video tutorial about how to do that:

    http://net.tutsplus.com/tutorials/php/how-to-create-blog-excerpts-with-php/

    0 讨论(0)
  • 2021-01-19 11:34

    What you're looking to do is called web scraping. The basic method for doing so would be to capture the page (you can scrape a URL using file_get_contents), and then somehow parse it for the content that you want (ie. pull out content from the <body> tag).

    In order to parse the returned HTML, you should use a DOM parser. PHP has its own DOM classes which you can use.

    0 讨论(0)
提交回复
热议问题