PHP Can I read web page text

4 replies
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
#page #php #read #text #web
  • Profile picture of the author imagetypers
    The best way to get contents from web page would be cURL library. It is much easier compared to file_get_contents.
    {{ DiscussionBoard.errors[11120095].message }}
  • Profile picture of the author prcheck
    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.
    {{ DiscussionBoard.errors[11124021].message }}
  • Profile picture of the author metabinltd
    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;
    {{ DiscussionBoard.errors[11124150].message }}
  • Profile picture of the author metabinltd
    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.
    {{ DiscussionBoard.errors[11124153].message }}

Trending Topics