Using the simple_html_dom_parser, I am trying to extract the teamId number from the anchor tags href attribute, using regular expression to check if the table cell has an anchor tag.
$rowData= array();
foreach($table->find('tr') as $row ){
$flight = array();
foreach ($row->find('td') as $cell){
if ($cell->find('a')){
foreach ($cell as $anchor)
$anchor = $cell->getAttribute('href');
$pattern = '/^.*?teamId=(\d+).*$/';
// write the pregmatch
preg_match_all($anchor, $pattern, $team_id);
//put the team_id into the end flight array
$flight[]= $team_id;
}
$flight[]= $cell->plaintext;
}
//pushes each TR into the array
$rowData[] = $flight;
}
When I run the script, I get an empty regular epression error. I've used RegEx checkers to make sure I'm using the correct identifiers for getting the teamId from the href url. I cant find out if im incorrectly using the DOM parser for selecting the href value or if it is a logical error.
This is the value of the href in the anchor tag: /ffl/clubhouse?leagueId=347987&teamId=15&seasonId=2015
I want to put the matched teamId into the $flight array along with the other td (or $cells) from the table