How to Iframe google map with PHP - php

I'm trying to 'iframe' a div using PHP / DOM instead showing the whole page, but I am having difficulties as the Div contains a custom google map and even when I try to show the entire page I am not able to make the map load. How is it possible to do it?
Link : http://satbeams.com/footprints?beam=5491
Div Id : "map_container"
What I have tried so far :
<?php
set_time_limit(0);
ini_set('memory_limit', '-1');
ini_set('display_errors',false);
include 'includes/dom.php';
$html = file_get_contents('http://satbeams.com/footprints?beam=5491');
$map = $html->find('div[map_container]');
echo $map;
?>
Thanks

file_get_contents returns a pure string, not an dom object you may manupilate. So have a look at http://php.net/manual/en/domdocument.loadhtml.php
A Google Map is mainly rendered via a javascript-API, so there isn't any existing iframe in the html markup that you could extract. You would have to parse the json data included in the page, and rebuild the map.
Be sure to not violate any copyrights!

Related

php simple html dom and iframe src

require('simple_html_dom.php');
// Create DOM from URL or file
$html = file_get_html('https://www7.fmovies.se/film/hometown-hero.m2r28/6xpjrp');
foreach($html->find('div[id=player]') as $div)
{
foreach($div->find('iframe') as $iframe)
{
echo $iframe->src;
}
}
This is my code and as you see I'm trying to get the src of the iframe under the player div using PHP Simple HTML DOM Parser, can you explain to me why I'm getting a blank page as a result?
Thanks!
UPDATE: After using a javascript switcher addon and disabling javascript, I noticed that the iframe I'm looking for is not loaded. What should I do to get the iframe src?
There are two possible solutions;
Try to figure out how the javascript works, and mock this behavior in your PHP script.
Let the page load in, for example, selenium and then grab the SRC from the iframe using selenium. (https://www.seleniumhq.org/)
Hope this helps

How can I update an element property using simple_html_dom

Id like to update the 'src' attribute of an img tag using Simple HTML DOM. Ive got his at the top of the php file (join.php) which contains the img file:
include_once("simplehtmldom/simple_html_dom.php");
$htmldomOb = file_get_html('join.php');
$htmldomOb->find('img[id=imgtapchat]', 0)->src = './tapchat/clss_tapcht-1.php';
echo $htmldomOb;
This works but outputs the entire page again since i read in the entire page dom object. How can i just update the image src similar to how it is done in jQuery - As it says in the SimpleHTMLDOM site docs
Find tags on an HTML page with selectors just like jQuery
With thanks
I use PHP Dom extension to rewrite PHP Simple Dom, just finished. You can try it here.
http://shinbonlin.github.io/html-parser/

i want to get data from another website and display it on mine but with my style.css

So my school has this very annoying way to view my rooster.
you have to bypass 5 links to get to my rooster.
this is the link for my class (it updates weekly without changing the link)
https://webuntis.a12.nl/WebUntis/?school=roc%20a12#Timetable?type=1&departmentId=0&id=2147
i want to display the content from that page on my website but with my
own stylesheet.
i don't mean this:
<?php
$homepage = file_get_contents('http://www.example.com/');
echo $homepage;
?>
or an iframe....
I think this can be better done using jquery and ajax. You can get jquery to load the target page, use selectors to strip out what you need, then attach it to your document tree. You should then be able to style it anyway you like.
I would recommend you to use the cURL library: http://www.php.net/manual/en/curl.examples.php
But you have to extract part of the page you want to display, because you will get the whole HTML document.
You'd probably read the whole page into a string variable (using file_get_contents like you mentioned for example) and parse the content, here you have some possibilities:
Regular expressions
Walking the DOM tree (eg. using PHPs DOMDocument classes)
After that, you'd most likely replace all the style="..." or class="..." information with your own.

Creating a personalization engine with php

I am new to php and I want to create an php engine which changes the web content of a webpage with PHP with the use of data in mysql. For example (changing the order of navigation links on a webpage with the order of highest click count) I am not sure how PHP will read the HTML file and change the elements in the HTML file and also output the HTML file with the changes. Is this possible?
I am not quite sure why you would want to generate the html, read it, change it and then output it. It seems to be a lot easier to just generate it the way you want to in the first place.
I am not sure how PHP will read the HTML file and change the elements in the HTML file and also output the HTML file with the changes. Is this possible?
You could use file_get_contents:
$html = file_get_contents($url);
Then use a html-parser like Simple HTML DOM Parser, change what you want to do and output it.
If you want to modify HTML structure, use ganon - HTML DOM parser for PHP
include('path/ganon.php');
// Parse the google code website into a DOM
$html = file_get_dom('http://code.google.com/');
foreach($html('p[class]') as $element) {
echo $element->class, "<br>\n";
}

Parsing HTML that has javascript with PHP

I'm trying to parse a HTML page where the majority of the content is contained in javascript. When I use the Chrome development tools I can see that the div class I'm trying to grab the content from is called div class=doodle-image. However when I either view the page as a source or try to grab it with php:
<?php
include_once('simple_html_dom.php');
$html = new simple_html_dom();
$html->load_file('http://www.google.com/doodles/finder/2012/All%20doodles');
$doodles = $html->find('.doodle-image');
echo $html;
?>
It returns the frame of the page but contains none of the divs or content. How can I grab the full content of the page?
That's because the element is empty when your PHP client fetches it, Google is loading in a JSON-object with JavaScript to populate the list of doodles. It does a Ajax-request to this page, and probably you can too.

Categories