0

I am using below mentioned php code to display images from webpages.Below mentioned code is able to display image url from main page but unable to display image urls from sub pages.

enter code here

<?php
include_once('simple_html_dom.php');
$target_url = "http://fffmovieposters.com/";
$html = new simple_html_dom();
$html->load_file($target_url);
foreach($html->find('img') as $img)
{
echo $img->src."<br />";
echo $img."<br/>";
}
?>
3
  • Have you tried changing $target_url to sub page? Like $target_url = "http://fffmovieposters.com/about" ? Commented Dec 8, 2014 at 10:58
  • use http path for all images..it will work Commented Dec 8, 2014 at 10:58
  • actually i don't have url of all sub links.Is it not possible that using code i will be able to get all sub link images? means code will automatically check all sub links under this domain. Commented Dec 8, 2014 at 11:01

1 Answer 1

1

If by sub-page you mean a page that http://fffmovieposters.com is linking to, then of course that script won't show any of those since you're not loading those pages.

You basically have to write a spider that not only finds images, but also anchor tags and then repeats the process for those links. Just remember to add some filters so that you don't process pages more than once or start processing the entire internet by following external links.

Pseudo'ish code

$todo = ['http://fffmovieposters.com'];
$done = [];
$images = [];

while( ! empty($todo))
    $link = array_shift($todo);
    $done[] = $link;
    $html = get html;
    $images += find <img> tags
    $newLinks = find <a> tags
    remove all external links and all links already in $done from $newLinks
    $todo += $newLinks;

Or something like that...

Sign up to request clarification or add additional context in comments.

8 Comments

Is possible please modify my code for sub links/sub pages requirement,actually i require url of .jpg images exist on whole website.
@tahirmehmood I gave you some pesudo code now, but you need to write your code yourself. I have my own job where I need to write code. You can check out my blog post on loading images (which takes relative URLs and such into account here: geekality.net/?p=1585, but you need to adjust it to process a full website recursively yourself.
thanks--please add in my existing code so that i will be able to test it on my server.
@tahirmehmood There is no code to test on your server until you have written that code. Pseudo code = rough draft of what you need to do, not actual code that works. You're probably paid to solve the problem you're trying to solve, so do your job and write the code :)
there is no payment involve in this case actually this is initial learn phase in start of my php scripting.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.