Hello,
I have created a simple PHP script using the simple_html_dom.php class. I fetch some information about movies from a website. I have one foreach loop inside another foreach loop. When I try to display the moviename inside the foreach loop I get the last moviename. What I want to achieve is to get each one of the unique movienames in each item. The problem is with the $movie variable.
(When i echo the $movie var on line 27 i get the correct result but I want to have each moviename inside the youtube links on line 33…)
<?php
include("simple_html_dom.php");
$tpb = 'https://tpb.party/search/2020/1/99/200';
$html = file_get_html(html_entity_decode($tpb));
foreach($html->find('tr.header') as $header) {
$header->outertext = '';
}
foreach($html->find('td') as $bottom) {
if ($bottom->colspan == '9') {
$bottom->outertext = '';
}
}
foreach($html->find('td.vertTh') as $vert) {
$vert->outertext = '';
}
foreach($html->find("div.detName") as $movie) {
$movie = $movie->plaintext;
echo $movie; //Works Okey, it displays each of the movietitles
foreach($html->find('img') as $img) {
if ($img->outertext == '<img src="https://tpb.party/static/img/11x11p.png" height="11" width="11">') {
$img->outertext = ' <a href="https://www.youtube.com/results?search_query='. $movie /* Doesn't work, only displays one title, not one each of the 30*/ .'" target="_blank"><img src="img/youtube.png" alt="Trailer" title="Trailer" style="width:19px;" width="19" height="18" border="0"></a>';
}
}
}
$html->save();
foreach($html->find("table") as $title) {
echo $title->outertext . '<br>';
}
?>