php HTMLテーブル各行各列を配列に変換してテーブルデータを収集する方法

1197 ワード

この例では、phpがHTMLテーブルの行ごとに列ごとに配列に変換してテーブルデータを収集する方法について説明します.皆さんの参考にしてください.具体的には以下の通りです.
次のphpコードは、HTMLテーブルの行ごとに列ごとに配列に変換し、テーブルデータを収集することができます.

]*?>'si","",$table);
  $table = preg_replace("']*?>'si","",$table);
  $table = preg_replace("']*?>'si","",$table);
  $table = str_replace("","{tr}",$table);
  $table = str_replace("","{td}",$table);
  //   HTML    
  $table = preg_replace("']*?>'si","",$table);
  //       
  $table = preg_replace("'([rn])[s]+'","",$table);
  $table = str_replace(" ","",$table);
  $table = str_replace(" ","",$table);
  $table = explode('{tr}', $table);
  array_pop($table);
  foreach ($table as $key=>$tr) {
    $td = explode('{td}', $tr);
    array_pop($td);
    $td_array[] = $td;
  }
  return $td_array;
}
?>

本稿で述べたphpプログラム設計に役立つことを願っています.