Could someone please tell me why this ain't working.
I'm trying to get a certain href and from a page by using php dom and that href - www.imdb.com/title/tt-some-id
contains the word imdb
so in the example below i try to get the href by using php function strpos
to look for the word imdb
but it don't seen to work.
$page = 'www.someurl.com';
$data = array();
$dom = new DOMDocument();
@$dom->loadHTML($page);
$data['imdb_link'];
$links = $dom->getElementsByTagName('a');
foreach ($links as $link) {
$href = $link->getAttribute('href');
if (false !== strpos($href,'imdb')) {
$data['imdb_link'] = $href;
} else {
$data['imdb_link'] = '';
}
}
And the links from the page
<a href="some-url.com"></a>
<a href="www.imdb.com/title/some-id"></a>
<a href="another-url.com"></a>
<a href="another-url.com"></a>
Could someone please tell me why it ain't working thanks