时间:2021-07-01 10:21:17 帮助过:21人阅读
$str='hhhhhhhhhhhhh
'
$str='jjjjjjjjjjjjjjjj
'
想要得到p或者h1之间的内容,怎么写?
形如:
$str='hhhhhhhhhhhhh
'
$str='jjjjjjjjjjjjjjjj
'
想要得到p或者h1之间的内容,怎么写?
([\s\S]+?)<\/\1>/';
$str='hhhhhhhhhhhhh
';
preg_match($reg, $str, $result);
var_dump($result);
$str='jjjjjjjjjjjjjjjj
';
preg_match($reg, $str, $result);
var_dump($result);
运行结果:
array(3) {
[0]=>
string(20) "hhhhhhhhhhhhh
"
[1]=>
string(1) "p"
[2]=>
string(13) "hhhhhhhhhhhhh"
}
array(3) {
[0]=>
string(25) "jjjjjjjjjjjjjjjj
"
[1]=>
string(2) "h1"
[2]=>
string(16) "jjjjjjjjjjjjjjjj"
}
$reg='#<([\w]+)>(.+?)<\/\1>#s'