Ask php to extract html list data using regular expressions

Source: Internet
Author: User
Ask php to extract html list data using regular expressions
Chengdu e-commerce Co., Ltd.Yang FA5101220001248473770103              Chengdu branch Technology Co., Ltd.Huang Canfa5110400017076766531815              


New php
Ask php to extract javascript: Detail ('r2013031500000871 ', '123') "with regular expressions and the values in td,
A tr is a row. it is best to put it in an array. thank you.


Reply to discussion (solution)

$ S = <
         Chengdu e-commerce Co., Ltd.Yang FA5101220001248473770103                                                                            Chengdu branch Technology Co., Ltd.Huang Canfa5110400017076766531815                                                                        Txt; preg_match_all ('/
  
   
] +> (. +) <\/Td>/sU ', $ s, $ m); print_r ($ m [1]); // The value of td is preg_match_all ('/
   

Oh, one print parameter is missing.
Preg_match_all ('/print_r ($ ar [1]); // parameter 1
Print_r ($ ar [2]); // parameter 2

Oh, one print parameter is missing.
Preg_match_all ('/print_r ($ ar [1]); // parameter 1
Print_r ($ ar [2]); // parameter 2

A tr is a row, because tr may be multiple rows in actual conditions. I want to match by tr and retrieve the values under each tr td line as an array.

preg_match_all('/
    
     ]+>\s*
     
      ]+>(.+)<\/td>\s*
      
       ]+>(.+)<\/td>\s*
       
        ]+>(.+)<\/td>\s*
        
         ]+>(.+)<\/td>\s*
         
          ]+>(.+)<\/td>\s*<\/tr>/sU',$s,$m,PREG_SET_ORDER);print_r($m);
         
        
       
      
     
    

preg_match_all('/
    
     ]+>\s*
     
      ]+>(.+)<\/td>\s*
      
       ]+>(.+)<\/td>\s*
       
        ]+>(.+)<\/td>\s*
        
         ]+>(.+)<\/td>\s*
         
          ]+>(.+)<\/td>\s*<\/tr>/sU',$s,$m,PREG_SET_ORDER);print_r($m);
         
        
       
      
     
    


                

In my last question, how do I write the following information about the R2013031500000871 and 671529939 in javascript: Detail ('r2013031500000871 ', '123?

#1. reply to the second question. isn't it?

#1. reply to the second question. isn't it?

I mean one match, no need to match again, that is, two regular expressions are merged together.

The result will be perfect.


Array ([0] => Array ([0] => Chengdu e-commerce Co., Ltd. [1] => Yang FA [2] => 51012200012484 [3] => 73770103 [4] => 012121400045944 [5] => 75203619) [1] => Array ...........

Preg_match_all ('/ ] +> \ S * ] +> (. +) <\/Td> \ s * ] +> (. +) <\/Td> \ s * ] +> (. +) <\/Td> \ s * ] +> (. +) <\/Td> \ s * ] +> (\ S *. +) <\/td> \ s * <\/tr>/sU ', $ s, $ m, PREG_SET_ORDER );
Print_r ($ m );

So?
Preg_match_all ('/ ] +> \ S * ] +> (. +) <\/Td> \ s * ] +> (. +) <\/Td> \ s * ] +> (. +) <\/Td> \ s * ] +> (. +) <\/Td> \ s * ] +> \ S *. + <\/td> \ s * <\/tr>/sU ', $ s, $ m, PREG_SET_ORDER );

So?
Preg_match_all ('/ ] +> \ S * ] +> (. +) <\/Td> \ s * ] +> (. +) <\/Td> \ s * ] +> (. +) <\/Td> \ s * ] +> (. +) <\/Td> \ s * ] +> \ S *. + <\/td> \ s * <\/tr>/sU ', $ s, $ m, PREG_SET_ORDER );

That's it. thanks a lot!

What tool did you use to test the regular expression? I used the Match Tracer and Expresso tests. the regular expression you wrote cannot Match, but it can be used in php, what does the last/sU mean?

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.