PHP regular html table array to save csv and conversion array code

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags array array_pop code csv function html network network programming

// html form each line into csv format array

<?
function get_tr_array ($ table) {

// php tutorial open source code

$ table = preg_replace ("'<td [^>] *?>' si ',' '', $ table);
$ table = str_replace ("</ td>", '",', $ table);
$ table = str_replace ("</ tr>", "{tr}", $ table); // Open Source osphp.com.cn
// remove the html tag
$ table = preg_replace ("'<[/!] *? [^ <>] *?>' si", "", $ table);
// remove whitespace characters
$ table = preg_replace ("'([rn]) [s] +'", "", $ table);


$ table = str_replace ("", "", $ table);
$ table = str_replace ("", "", $ table);
$ table = explode (", {tr}", $ table);

array_pop ($ table);
return $ table;
}
?>

// Convert each column of the html table into an array and collect the table data

<?
function get_td_array ($ table) {
$ table = preg_replace ("'<table [^>] *?>' si", "", $ table);

//osphp.com.cn

$ table = preg_replace ("'<tr [^>] *?>' si", "", $ table);
$ table = preg_replace ("'<td [^>] *?>' si", "", $ table);
$ table = str_replace ("</ tr>", "{tr}", $ table); // Open Source osphp.com.cn
$ table = str_replace ("</ td>", "{td}", $ table);
// remove the html tag
$ table = preg_replace ("'<[/!] *? [^ <>] *?>' si", "", $ table); //osphp.com.cn Open Source
// remove whitespace characters
$ table = preg_replace ("'([rn]) [s] +'", "", $ table);
$ table = str_replace ("", "", $ table);

$ table = str_replace ("", "", $ table);
$ table = explode ('{tr}', $ table);
array_pop ($ table); // php open source
foreach ($ table as $ key => $ tr) {
$ td = explode ('{td}', $ tr);
array_pop ($ td);
$ td_array [] = $ td; //}
return $ td_array;
}
?>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.