So I was looking for a way to be able to parse images (<img>) from a
given url. It so happened that I stumbled upon a nice little piece of
code called "PHP Simple HTML DOM Parser" found here :
On the first page, I made a form where you can enter a URL, and then
the script tries to fetch the images.
It was indeed what I needed. A simple code like this did a portion of
the job:
<?php
include('simple _html_dom.php') ; // This
is the script, download it on their sourceforge.
// Create DOM from URL or file
$dom = file_get_dom('h ttp://www.google.com' ); // In my code,
this was replaced by a url variable.
// Find all <img>
foreach($dom->find('img') as $element)
echo $element->src . "<br />" ;
$dom->clear();
unset($dom);
?>
I understood the code, but I'm still a newbie in PHP. What I still
want to do is:
*Be able to specify that it only fetches .jpeg files for example.
*Only allow images that are bigger than a certain dimensions.
*For now it only gives me the URL (relative or absolute, depending on
the html of the source). What I also want is that it displays the
images parsed.
This is mainly for educational purposes, as the best way to learn PHP
is to keep writing small applications with it. So if anyone can point
me in the right direction, it'll be great. And if you know of another
script with the same functionality, it'll be great, I like learning
different ways to achieve something.
Thanks!
given url. It so happened that I stumbled upon a nice little piece of
code called "PHP Simple HTML DOM Parser" found here :
On the first page, I made a form where you can enter a URL, and then
the script tries to fetch the images.
It was indeed what I needed. A simple code like this did a portion of
the job:
<?php
include('simple _html_dom.php') ; // This
is the script, download it on their sourceforge.
// Create DOM from URL or file
$dom = file_get_dom('h ttp://www.google.com' ); // In my code,
this was replaced by a url variable.
// Find all <img>
foreach($dom->find('img') as $element)
echo $element->src . "<br />" ;
$dom->clear();
unset($dom);
?>
I understood the code, but I'm still a newbie in PHP. What I still
want to do is:
*Be able to specify that it only fetches .jpeg files for example.
*Only allow images that are bigger than a certain dimensions.
*For now it only gives me the URL (relative or absolute, depending on
the html of the source). What I also want is that it displays the
images parsed.
This is mainly for educational purposes, as the best way to learn PHP
is to keep writing small applications with it. So if anyone can point
me in the right direction, it'll be great. And if you know of another
script with the same functionality, it'll be great, I like learning
different ways to achieve something.
Thanks!
Comment