Search code examples
loadexternalhtml

How Can I load a specific DIV from an external webpage, into a specific DIV of my website?


I Want to load a Specific Div of an external webpage into a specific Div (No iframe) Of my own website. for example: I have a div like this in my own website:

<div id="weather-status"> Weather Status </div>

I have this site too: http://www.timeanddate.com/weather/ and I want to load a table from this site (http://www.timeanddate.com/weather/) into my div (Weather Status) How Can I Do This?


Solution

  • <?php
       $url = "http://www.timeanddate.com/weather/";
       $page_all = file_get_contents($url); 
    
       preg_match('#<table class="border2 lpad wa">(.*)</table>#ms', $page_all, $div_array);
    
    
       echo "<pre>";
       print_r($div_array[0]);
       echo "</pre>";
    ?>
    

    With the following CSS :

    .wa {
        margin: 0 auto;
    }
    
    .border2 {
        background: none repeat scroll 0 0 #D7D6DC;
    }
    
    .lpad tr td {
        padding: 0.2em;
    }