foreach($div->getElementsByTagName('a') as $link) {
$url = $link->getattribute('href');
$num = $link->nodeValue;
echo '<source src="'.$url.'" type="video/mp4" label="----quality----" />';
}
The video link is repeated 5 times .. I want to add quality to each video [240-360-480-720-1080] .. I searched a lot and did not find a solution to my problem and I hope that there is an example
CodePudding user response:
Use the index in the foreach
and then use this as the index into an array of qualities.
$qualities = [240, 360, 480, 720, 1080];
foreach($div->getElementsByTagName('a') as $index => $link) {
$url = $link->getattribute('href');
$num = $link->nodeValue;
$quality = $qualities[$index];
echo '<source src="'.$url.'" type="video/mp4" label="----' . $quality . '----" />';
}