$str = '内容A 内容B'
请问一下,用正则分别取出 内容A 跟 内容B 正则要怎样写呢?
注:内容A,内容B 中间会有换行符。
回复讨论(解决方案)
你要得到的事内容A和内容B呢,还是 id="test_0"的text和 id="test_1"的内容呢?
内容A 与 内容B
跟ID无关。不是JS。是PHP取数据。
$subject = ' you dead! hello james shit! hi
- list
- list
$str = '内容A内容B';
preg_match_all('/(.*?)<\/div>/i',$str,$match);
echo $match[2][0];//内容A
echo $match[2][1];//内容B
默默收藏
preg_match_all('/(.*?)<\/div>/is',$subject,$match);
var_dump($match);
preg_match_all('/(.*?)<\/div>/is',$subject,$match);
var_dump($match);
好像有点问题。不是很准。
array(3) { [0]=> array(2) { [0]=> string(86) " you dead! hello" [1]=> string(80) " shit! hi" } [1]=> array(2) { [0]=> string(12) " id="test_0"" [1]=> string(12) " id="test_1"" } [2]=> array(2) { [0]=> string(45) " you dead! hello" [1]=> string(39) " shit! hi" }}
少了〈/div〉
preg_match_all('/(\s*(?:\s*)*)<\/div>/us',$subject,$match);echo $match[0][0];echo '
';echo $match[0][1];
<?php$subject = ' you dead! hello james shit! hi
- list
';echo $match[0][1];
<?php$subject = ' you dead! hello james shit! hi
- list
';echo $match[0][1]; 膜拜大神!