PHP Can I read web page text

by 4 replies
5
I don't mean file_get_contents. I was wondering if there's a simple script to get the first 200 characters of the text from a web page? I want to include it into a description for an rss feed.

Rick
#programming #page #php #read #text #web
  • The best way to get contents from web page would be cURL library. It is much easier compared to file_get_contents.
    • [ 1 ] Thanks
  • Using curl is a good way to go, on the other way round, you can still use file_get_contents to get the content of the page, use strip_tags to extract only text from html and then use script to get the first 200 characters.
    • [ 1 ] Thanks
  • This is a quick hack, but it won't work when the content is generated via javascript.
    $url='http://www.youtube.com/';
    $content=substr(strip_tags(preg_replace('#<(((no)? script)|style)(.*?)>(.*?)</\1>#is','',file_get_contents($url))),0,200);
    echo $content;
    • [ 1 ] Thanks
  • The best option is to install these packages on your server: phantomjs casperjs slimerjs and use one of the composer packages: microweber/screen phpcasperjs/phpcasperjs to control them.
    • [ 1 ] Thanks
  • [DELETED]
    • [ 1 ] Thanks

Next Topics on Trending Feed

  • 5

    I don't mean file_get_contents. I was wondering if there's a simple script to get the first 200 characters of the text from a web page? I want to include it into a description for an rss feed. Rick