.body{
align: center;
font-size: 10pt;
background: #CCCDDC;
background-image: url(http://localhost/images/test1.png);
background-repeat: repeat-x;
}
.body{
align: center;
font-size: 10pt;
background: #CCCDDC;
background-image: url(http://localhost/images/test2.png);
background-repeat: repeat-x;
}
.body{
align: center;
font-size: 10pt;
background: #CCCDDC;
background-image: url(http://localhost/images/test3.png);
background-repeat: repeat-x;
}我想获取到这个值
{
align: center;
font-size: 10pt;
background: #CCCDDC;
background-image: url(http://localhost/images/test2.png);
background-repeat: repeat-x;
}大概匹配规则就是:{ + 一堆字符串 + test2.png + 一堆字符串 + }怎么匹配,有些急
align: center;
font-size: 10pt;
background: #CCCDDC;
background-image: url(http://localhost/images/test1.png);
background-repeat: repeat-x;
}
.body{
align: center;
font-size: 10pt;
background: #CCCDDC;
background-image: url(http://localhost/images/test2.png);
background-repeat: repeat-x;
}
.body{
align: center;
font-size: 10pt;
background: #CCCDDC;
background-image: url(http://localhost/images/test3.png);
background-repeat: repeat-x;
}我想获取到这个值
{
align: center;
font-size: 10pt;
background: #CCCDDC;
background-image: url(http://localhost/images/test2.png);
background-repeat: repeat-x;
}大概匹配规则就是:{ + 一堆字符串 + test2.png + 一堆字符串 + }怎么匹配,有些急
$str = <<<STR
.body{
align: center;
font-size: 10pt;
background: #CCCDDC;
background-image: url(http://localhost/images/test1.png);
background-repeat: repeat-x;
}
.body{
align: center;
font-size: 10pt;
background: #CCCDDC;
background-image: url(http://localhost/images/test2.png);
background-repeat: repeat-x;
}
.body{
align: center;
font-size: 10pt;
background: #CCCDDC;
background-image: url(http://localhost/images/test3.png);
background-repeat: repeat-x;
}
STR;
$patten = '/({[^{]+test2.png[^{]*})/i';
preg_match_all($patten,$str,$arr);
echo "<pre>";
print_r($arr[1]);
$str = <<<STR
.body{
align: center;
font-size: 10pt;
background: #CCCDDC;
background-image: url(http://localhost/images/test1.png);
background-repeat: repeat-x;
}
.body{
align: center;
font-size: 10pt;
background: #CCCDDC;
background-image: url(http://localhost/images/test2.png);
background-repeat: repeat-x;
}
.body{
align: center;
font-size: 10pt;
background: #CCCDDC;
background-image: url(http://localhost/images/test3.png);
background-repeat: repeat-x;
}
STR;
preg_match_all('/\{.*test2\.png.*\}/isU', $str, $matches);
print_r($matches[0]);
/**
输出结果:Array ( [0] => { align: center; font-size: 10pt; background: #CCCDDC; background-image: url(http://localhost/images/test1.png); background-repeat: repeat-x; } .body{ align: center; font-size: 10pt; background: #CCCDDC; background-image: url(http://localhost/images/test2.png); background-repeat: repeat-x; } )
*/