Home > Backend Development > PHP Tutorial > PHP converts each row and column of an HTML table into an array to implement the method of collecting table data_PHP tutorial

PHP converts each row and column of an HTML table into an array to implement the method of collecting table data_PHP tutorial

WBOY
Release: 2016-07-13 09:58:04
Original
823 people have browsed it

php converts each row and column of an HTML table into an array to collect table data

This article describes an example of how php converts each row and column of an HTML table into an array to collect the table data methods. Share it with everyone for your reference. The details are as follows:

The following php code can convert each row and column of the HTML table into an array and collect table data

<?php
function get_td_array($table) {
  $table = preg_replace("'<table[^>]*?>'si","",$table);
  $table = preg_replace("'<tr[^>]*?>'si","",$table);
  $table = preg_replace("'<td[^>]*?>'si","",$table);
  $table = str_replace("</tr>","{tr}",$table);
  $table = str_replace("</td>","{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;
}
?>
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/979234.htmlTechArticlephp converts each row and column of the HTML table into an array to implement the method of collecting table data. This article describes the example of how php converts HTML Each row and column of the table is converted into an array to implement the method of collecting table data. Share with everyone...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template