I have the code below that basically reads Spotify Charts table and prints it.
What I want to do now is only print rows from a specific artist, e.g. Post Malone. So 'Post Malone
' would have to be on the row array. I tried it several ways, but nothing works. Can anyone give me a light in which direction to go?
<?php
include_once('../simple_html_dom.php');
$html = file_get_html('https://spotifycharts.com/regional/us/daily/latest');
$table = $html->find('table', 0);
$rowData = array();
foreach($table->find('tr') as $row) {
$onerow = array();
foreach($row->find('td') as $cell) {
$onerow[] = $cell->plaintext;
}
$rowData[] = $onerow;
}
echo '<table>';
foreach ($rowData as $row => $tr) {
echo '<tr>';
foreach ($tr as $td)
echo '<td>' . $td .'</td>';
echo '</tr>';
}
echo '</table>';
?>
答案 0 :(得分:1)
foreach($row->find('td') as $cell) {
if(strpos($cell->(your name column),"Post Malone") !== false){
$onerow[] = $cell->plaintext;
}
}
试试这个