Regular small problem

Source: Internet
Author: User
This post was last edited by Snipersheep on 2013-08-01 15:52:47

$str = ' content a content B '
May I ask how to write the content A and content B in regular order?
Note: Content A has a newline character in the middle of content B.


Reply to discussion (solution)

What do you want to get content A and content B, or id= "test_0" text and id= "test_1" content?

Content A and Content B
Has nothing to do with ID. Not JS. is PHP fetch data.

$subject = ' You dead!helloJames            Shit!hi
 
  
  
  • List
'; $pattern = '/Here is how to write/';p reg_match ($pattern, $subject, $matches);p Rint_r ($matches), $pattern _1 = '/Here is how to write/';p Reg_ Match ($pattern _1, $subject, $matches);p Rint_r ($matches) and fetch the result as follows: Data one: You Dead!helloJames Data II: SHIT!HI
  • List

$str = ' content a content B ';
Preg_match_all ('/(. *?) <\/div>/i ', $str, $match);
echo $match [2][0];//content A
echo $match [2][1];//content B

Silent Collection

Preg_match_all ('/(. *?) <\/div>/is ', $subject, $match);
Var_dump ($match);

Preg_match_all ('/(. *?) <\/div>/is ', $subject, $match);
Var_dump ($match);

There seems to be a problem. Not very accurate.

Array (3) {  [0]=>  Array (2) {    [0]=>    string (*) "You Dead!hello"    [1]=>    string (80) " Shit!hi "  }  [1]=>  Array (2) {    [0]=>    string ()" Id= "Test_0" "    [1]=>    string ( "Id=" Test_1 ""  }  [2]=>  Array (2) {    [0]=>    string () "You Dead!hello"    [1]= >    string (Shit!hi)}  }

Less 〈/div〉.

Preg_match_all ('/(\s* (?: \ s*) <\/div>/us ', $subject, $match); Echo $match [0][0];echo '
 
  '; Echo $match [0][1];

 
  James                                        shit!                Hi                
 
  
  
  • List
';p reg_match_all ('/]+> ([^<]*|< (?! DIV) | (? R) +) <\/div>/us ', $subject, $match); Echo $match [0][0];echo ' '; Echo $match [0][1];

 
  James                                        shit!                Hi                
 
  
  
  • List
';p reg_match_all ('/]+> ([^<]*|< (?! DIV) | (? R) +) <\/div>/us ', $subject, $match); Echo $match [0][0];echo ' '; Echo $match [0][1];
Worship the Great God!
  • 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.