get file contents : php help needed

by 9 replies
11
hello,

am trying to access html content using php ( using get_file_contents ) but it's seems too slow .. i need text only how can i access text only using this ?
#programming #contents #file #needed #php
  • What are you really trying to do?
    Read an external or a local web page and then strip out the html?
    Or something else?
    Why don't you post an example of the code? It would be helpful.
    • [1] reply
    • get_file_contents('external URL') ;

      i need only plain text , any other function ?
      • [1] reply
  • You can use CURL, but its still going to be slow, since you are going to an external site.
    • [ 1 ] Thanks
    • [1] reply
    • You should follow him.
  • You can't make the process faster, what you can do is actually cache the results for some time (or forever) so you wont have to load the data each time someone visits the page.

    You can do that by saving the data in files or in your database.
    • [ 1 ] Thanks
  • Use this to remove html:

    PHP: strip_tags - Manual

    so you would do something like:

    $html = file_get_contents('http://www.example.com/');
    $text = strip_tags($html);

    Refer to the documentation for the details and some possible improvements as well.
    • [1] reply
    • To speed up the process, please use socket. The issue is network connection speed, a augmentation using strip_tags(.) will not help.
  • Hello junly,
    Do you make multiple http calls on a page load or just one? If you have multiple ones, I suggest you to use the Rolling Curl Class => rolling-curl - A more efficient multi-curl library for PHP (non-blocking) - Google Project Hosting this will make multiple requests at the same time so it will be finished faster.

    Cheers

Next Topics on Trending Feed