0

嗨,我真的找不到答案。我有几个变量想在 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">';
}

但不工作有人可以帮我吗?谢谢!

4

1 回答 1

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">';
}
于 2013-08-07T23:41:52.333 回答