How can I update an element property using simple_html_dom - php

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/

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

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.

Extract all links which ends with .js extension in html page

I want to extract all links that ends with .js within html page.I am able to fetch links that are within script tag
but how could i fetch links from properties like {"yui":"http://l.yimg.com/nn/lib/metro/g/uicontrib/yui/yui_3.4.1.js"}.
I want this to be done in php
A simple PHP HTML DOM parser written in PHP5+, supports invalid HTML, and provides a very easy way to handle HTML elements. Find tags on an HTML page with selectors just like jQuery. Extract contents from HTML in a single line.
Here is the link to get it: http://sourceforge.net/projects/simplehtmldom/
...and here is the official web site: http://simplehtmldom.sourceforge.net/
For basic HTML elements you can use http://code.google.com/p/phpquery/ to parse DOM content (it handle jquery like CSS selectors, functions like attr, find). Here is example howto use selectors with PhpQuery http://code.google.com/p/phpquery/wiki/Selectors.
For properties, it depends:
Some kind of regexp if they are in Javascripts or something else,
If they are in data attributes and you know attributes name, then you can get that json string and simply run json_decode php function on it.

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";
}

Getting the first URL of an image search result with google image API in PHP

did you know a php script (a class will be nice) who get the url of the first image result of a google api image search? Thanks
Example.
<?php echo(geturl("searchterm")) ?>
I have found a solution to get the first image from Google Image result using Simple HTML DOM as Sarfraz told.
Kindly check the below code. Currently it is working fine for me.
$search_keyword=str_replace(' ','+',$search_keyword);
$newhtml =file_get_html("https://www.google.com/search?q=".$search_keyword."&tbm=isch");
$result_image_source = $newhtml->find('img', 0)->src;
echo '<img src="'.$result_image_source.'">';
You should be able do that easily with Simple HTML DOM.
Note: See the examples on their site for more information.
A HTML DOM parser written in PHP5+ let you manipulate HTML in a very easy way!
Find tags on an HTML page with selectors just like jQuery.

Categories