ToCode
ToCode

Reputation: 57

Use PHP Simple HTML DOM Parser to find .zip?

I'm new to PHP Simple HTML DOM Parser and I'm trying to list links that end in .zip and -animal.jpg but I'm not sure how to do it.

I've tried searching on google but to no avail, all I get from below is a white page.

// Create DOM from URL or file
$html = file_get_html('<domain removed>');

// Find all -animal image files
foreach($html->find('-animal.jpg') as $element)
echo $element->href . '<br>';

// Find all zip files
foreach($html->find('.zip') as $element)
echo $element->href . '<br>';

Upvotes: 1

Views: 208

Answers (1)

Kevin
Kevin

Reputation: 41893

You could use strpos() to search for that particular href. Example:

$links = $html->find('a');
foreach($links as $link) {
    if(
        (strpos($link->href, '-animal.jpg') !== false) ||
        (strpos($link->href, '.zip') !== false)
    ) {
        echo $link->href . '<br/>';
    }
}

Upvotes: 3

Related Questions