get file contents : php help needed

9 replies
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 ?
#contents #file #needed #php
  • Profile picture of the author KirkMcD
    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.
    {{ DiscussionBoard.errors[5191654].message }}
    • Profile picture of the author rahman.warrior
      Originally Posted by KirkMcD View Post

      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.
      get_file_contents('external URL') ;

      i need only plain text , any other function ?
      {{ DiscussionBoard.errors[5191775].message }}
      • Profile picture of the author 2WDHost
        Originally Posted by junly View Post

        get_file_contents('external URL') ;

        i need only plain text , any other function ?
        Check PHP Simple HTML DOM Parser. It can help you to extract the content you need from HTML page.
        Signature
        2WDH.com: Professional cPanel Hosting since 2003
        Really helpful support. You're not a number to us! Programming, database and site development help.
        No overselling. SSD. Real 99.99%+ uptime. Free 2-week trial: no obligation/credit card required.
        {{ DiscussionBoard.errors[5192657].message }}
  • Profile picture of the author KirkMcD
    You can use CURL, but its still going to be slow, since you are going to an external site.
    {{ DiscussionBoard.errors[5192256].message }}
  • Profile picture of the author Nikolas
    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.
    {{ DiscussionBoard.errors[5192362].message }}
  • Profile picture of the author DannyDarwin
    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.
    {{ DiscussionBoard.errors[5192678].message }}
    • Profile picture of the author tinyraysite
      To speed up the process, please use socket. The issue is network connection speed, a augmentation using strip_tags(.) will not help.
      Signature
      {{ DiscussionBoard.errors[5206405].message }}
  • Profile picture of the author SeeSharp
    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
    {{ DiscussionBoard.errors[5206528].message }}

Trending Topics