嗨,我真的找不到答案。 我有一个我想在preg_match中使用的变量,但我只能使用一个变量。
我的代码是:
function imagetoday(){
global $imagetoday;
if(preg_match_all('/rain.png/', $imagetoday)){
echo '<img src="assets/img/rain.png" class="img-responsive week" alt="Responsive image">';
}
if(preg_match('/light_rain.png/', $imagetoday)){
echo '<img src="assets/img/light_rain.png" class="img-responsive week" alt="Responsive image">';
}
if(preg_match('/partly_cloudy.png/', $imagetoday)){
echo '<img src="assets/img/partly_cloudy.png" class="img-responsive week" alt="Responsive image">';
}
}
我尝试使用
if(preg_match('/light_rain.png/', $imagetoday, $imageday2, imageday3, $imageday4)){
echo '<img src="assets/img/light_rain.png" class="img-responsive week" alt="Responsive image">';
}
但不起作用有人可以帮助我吗?谢谢!
答案 0 :(得分:1)
if (preg_match('/(?:(?:light_)?rain|partly_cloudy)\.png/', $imagetoday, $match)) {
echo '<img src="assets/img/' . $match[0]
. '" class="img-responsive week" alt="Responsive image">';
}