Parsing text within iframe

Posted on 2007-10-16
Last Modified: 2008-01-09
How do I parse a text string on a web page with an iframe? The string is within the iframe.

What I am trying to do is determine whether the iframe is properly loading. Then if it is not write a timestamp and error message to the disk.
Question by:sparkie_77
    LVL 1

    Expert Comment

    Please littlebit explain more about your problem with iframe and then we will definitely give you the appropriate solution of code.

    LVL 7

    Accepted Solution

    Are you wanting to test a remote page from your script? If your wanting to test like that just use preg_match() like this:

    $iframe = array();

    $url = '';

    $ch_one = curl_init();
    curl_setopt($ch_one, CURLOPT_URL, $url);
    curl_setopt($ch_one, CURLOPT_REFERER, '');
    curl_setopt($ch_one, CURLOPT_HEADER, 1);
    curl_setopt($ch_one, CURLOPT_FOLLOWLOCATION, 0);
    curl_setopt($ch_one, CURLOPT_USERAGENT, "$_SERVER[HTTP_USER_AGENT]");
    curl_setopt($ch_one, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch_one, CURLOPT_TIMEOUT, 5);
    $result_one = curl_exec($ch_one);

    preg_match("/<iframe>(.*?)'</iframe>/", $result_one, $iframe);

    //Now $iframe is an array and your parsed result of everything between the <iframe> tags is stored in the array location [1]. You can now run tests againts this such as this.

    if (strlen($iframe[1] == '0') {
        //nothing was loaded , do something. Now to make sure you didnt get a partial load or anything it would probably be a good idea to keep a cache copy of the html to compare against stored on your end that gets updated every so often and compare what was loaded like so.
    } elseif ($iframe[1] != $url.cache) {
        //What was loaded did not match what we expected. Do something.

    Maybe that will point you in the right direction. :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    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!

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    737 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

    20 Experts available now in Live!

    Get 1:1 Help Now