Php regular html table array save csv and convert array code-PHP source code

Source: Internet
Author: User
Ec (2); convert each line of an html table into an array in csv format & lt ;? Functionget_tr_array ($ table) {php tutorial source code $ tablepreg_replace (& quot; & lt; td [^ & gt;] *? & Gt; si & quot;, & quot;, $ table); $ tablestr_replace (& quot; & lt; td & gt; & script ec (2 ); script

// Convert each line of the html table into an array in csv format

Function get_tr_array ($ table ){

// Php tutorial source code

$ Table = preg_replace ("' ] *?> 'Si ", '"', $ table );
$ Table = str_replace ("", '",', $ Table );
$ Table = str_replace (""," {Tr} ", $ table); // open-source osphp.com.cn
// Remove the html Tag
$ Table = preg_replace ("'<[/!] *? [^ <>] *?> 'Si "," ", $ table );
// Remove the white space 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 row and column of an html table into an array to collect table data

Function get_td_array ($ table ){
$ Table = preg_replace ("' ] *?> 'Si "," ", $ table );

// Osphp.com.cn

$ Table = preg_replace ("' ] *?> 'Si "," ", $ table );
$ Table = preg_replace ("' ] *?> 'Si "," ", $ table );
$ Table = str_replace (""," {Tr} ", $ table); // open-source osphp.com.cn
$ Table = str_replace (""," {Td} ", $ table );
// Remove the html Tag
$ Table = preg_replace ("'<[/!] *? [^ <>] *?> 'Si "," ", $ table); // osphp.com.cn Open Source
// Remove the white space 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 code
Foreach ($ table as $ key => $ tr ){
$ Td = explode ('{td}', $ tr );
Array_pop ($ td );
$ Td_array [] = $ td ;//}
Return $ td_array;
}
?>

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.