The html snippet in a url (www.foo.com/index.html):
...
<th class="name" align="left" scope="col">
<a class="foo" href="foo.html">foo</a>
</th>
...
<th class="name" align="left" scope="col">
<a class="bar" href="bar.html">bar</a>
</th>
...
<th class="name" align="left" scope="col">
<a class="ba" href="baz.html">baz</a>
</th>
......
I would like to get, through php all the text inside the class .name and convert it to JSON
So that it ends up like:
{"names":["foo","bar","baz"]}
This is what I have tried:
function linkExtractor($html){
    $nameArr = array();
    $doc = new DOMDocument();
    $doc->loadHTML($html);
    $names = //how do i get the elements?
    foreach($names as $name) {
        array_push($nameArr, $name);
    }
    return $imageArr;
}
echo json_encode(array("names" => linkExtractor($html)));
 
     
    