simple_html_dom_parserを使用して、表のセルにアンカータグがあるかどうかを確認する正規表現を使用して、anchorタグのhref属性からteamId番号を抽出しようとしています。preg_match_allを使用して値のhrefを確認する方法
$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;
}
スクリプトを実行すると、空の通常のエフェクトエラーが発生します。 RegExチェッカーを使用して、href urlからteamIdを取得するための正しい識別子を使用していることを確認しました。私は間違ってhrefの値を選択するためにDOMパーサーを使用している場合、またはそれが論理的なエラーであるかどうかを調べることはできません。
これは、アンカータグのhrefの値です:? /FFL /クラブハウスleagueId = 347987 & teamId = 15 & seasonId = 2015
私は一緒に$飛行配列にマッチしたteamIdを入れたいですテーブル
なぜ正規表現を使用していますか?なぜあなたは文字列にアクセスして分割しないのですか? 'explode( '='、explode( '&'、explode( '?'、$ urlstring)[1]))[1]'は上記の例から結果 '15'を返します。 – junkfoodjunkie