How to save web-pages using php

Posted on 2004-11-08
Last Modified: 2008-03-06
For example i have text input, and i want once user type any url there my script to save this website in to "cache" directory on my sarver and then show it in the iframe in my script. Does any one got any clue how can I do this. Some code examples will be great...
Question by:g00r00
    1 Comment
    LVL 7

    Accepted Solution

    You can use the 'file' function both ways:

    TO capture the web page, use


    To write the stuff to a file,

    print("<iframe src=\"show.php?fn=".urlencode($filecode)."\">");

    To display the text in an IFRAME, use the follow file as 'show.php':
    preg_replace("#/\. #","",$fn);

    Note that if there are relative URLs in the HTML file that you have thus downloaded then they might not display properly. You can play around with the <BASE> tag in HTML or else use some regexps to fix up the locations of the images. But even then some servers will not allow images to be loaded unless being requested from a local referrer. So you might have some problems possibly.

    The full-blown approach is to use a class which emulates a browser. I have found the following to be really solid:

    Hope that helps


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to dynamically set the form action using jQuery.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now