Hey guys I'm wondering how I would be able to grab only the first image on a page. I want to echo it somewhere else possibly as a variable.
well I have not attempted this before, but I found a website that looks like it gives a pretty good solution. if you are trying to copy the first image from a URL. http://phpsnips.com/snippet.php?id=61
hope that helps. :)
You use PHP's DOMDocument class to grab the page's source, use an XPath query with DOMDocument to get the first img tag, then grab its src attribute.
http://php.net/manual/en/class.domdocument.php
You can then use that to save the url, or download the file.
Related
I have a website with this li:
<li id="video1" class="streamList Playclick rippler rippler-inverse" data-url="http://54.39.16.47:25461/live/674475857/674475857/461.m3u8">
I need to extract the data-url value of it, am using simple_html_dom.php to scrape into the page.
have someone work do it with simple_html_dom.php? will be able to help me with an example of how to extract it?
Are you using this SimpleHtmlDom?
If yes, try it like in the examples (untested by me)
$html->find('li[id=video1]')->getAttribute('data-url')
I have a php file that outputs a image with dynamic content.
I need to get the url of the img using it. Example: www.bla.com/
<img src="signature.php?color=black">
The php would return www.bla.com/
Can I do this WITHOUT using GET vars and php on the img page?
Thanks to #Terminus for helping, my solution was to use:
$_SERVER["HTTP_REFERER"]
Then do some sanitizing just in case.
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.
Hi I am currently doing my website to pull all instagram photo into my web.
this is my code:
<div id="instafeed"></div>
<script type="text/javascript">
new Instafeed({
get: 'tagged',
tagName: 'awesome',
clientId: 'xxx',
image_size: 'standard_resolution',
}).run();
</script>
How do I get the url/path of the photo that i pulled inside my site?
Is it something about JSON? but i dont know what is it anyone can give me a hint?
Thanks!
You could use a webcrawler to pull the information you need from website.
Here is a nice tutorial. You need to specify the url and the desired html tag.
<?php
include_once('simple_html_dom.php');
$html = new simple_html_dom();
$html->load_file($target_url);
foreach($html->find('img') as $link)
{
echo $link->href."<br />";
}
Moreover you should look over cURL to improve you webcrawler.
EDIT:
#youaremysunshine
the code above is from the tutorial i suggested you look at. 'simple_html_dom.php' is a file that you need to download (you can find it in the tutorial) in order to use its functions.
So, after you include the file, you simply create a new simple_html_dom object and call the function load_file() with the desired url as a parameter. $html->find('img') looks for the <img> tag from the given page. Try to read the tutorial a few times and you may need to look up for part 2. Go to the website with the desired image and inspect element to see wich element you need to use for the find() function (the parameter may also contain the class/id of the searched element).
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.