PHP obtains the creation of a general program for any table on the webpage.
Source: Internet
Author: User
Reprinted please contact the author: E-mail: pengwuwang@21cn.comdarlingpeng @ sina.com in the work, often need to deal with the content of the form on the web page, but because of the casual process of table content, cross-row and cross-column is often generated, so I made these letters reproduced please contact the author: Email: pengwuwang@21cn.com darlingpeng@sina.com
In my work, I often need to process the table content on the webpage. However, because of the casual nature of the table content during the process, cross-row and cross-column operations are often generated, I have made these functions, in order to get the table content, the important places in the program have been annotated, so I will not repeat the clarification here. after testing, it is very successful. so we can share it with you. // Author: Wang pengwu
// Date: November 3, 31
// Target: obtain the content function fun_proc_rowspan ($ l_str) in the table on the webpage (any cross-row cross-column)
{
$ L_a = explode ('\ n', $ l_str );
For ($ I = count ($ l_a)-1; $ I> = 0; $ I --){
$ L_str = trim ($ l_a [$ I]);
If (empty ($ l_str) continue;
$ L_str = eregi_replace (' $ L_ B = explode ('
', $ L_str); // if there are n, Is divided into (n 1) groups, the first item is empty. For ($ j = 0; $ j For example ---------------------------- ---- This row retains 7 cells, and the first 6 cells have rowspan = 2. ----------------------------- This row only keeps 2 cells ---------------------------------- This row only keeps 1 cell */ $ L_str = trim ($ l_ B [$ j]); If (eregi ('rowspan ', $ l_str )){ $ Rowspan = preg_replace ('/^ $ Rowcont = preg_replace ('/^ (.) <\/Td>/',' \ 1', $ l_str ); $ L_a = fun_add_row_td ($ l_a, $ I, $ j, $ rowspan, $ rowcont ); $ L_str = implode ('\ n', $ l_a ); Return $ l_str; } } // End of for j } // End of for I Return $ l_str; } Function fun_add_row_td ($ l_a, $ r, $ l, $ add_n, $ add_cont) // Rochelle A is an array, r is the start row inserted, and l is the start column, the number of rows that add_n spans and add_cont is the added content. { For ($ I = $ r; $ I <$ r $ add_n; $ I ){ If ($ I = $ r ){ $ L_str = eregi_replace (' $ L_ B = explode (' ', $ L_str ); $ L_c = ''; For ($ j = 1; $ j If ($ j = $ l) $ l_c. = eregi_replace ('rowspan ', '', $ l_ B [$ j]); // drop rowspan Else $ l_c. = $ l_ B [$ j]; } $ L_a [$ I] = $ l_c; Continue; } $ L_str = eregi_replace (' Delimiter
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