在此正则表达式的末尾添加<img src="*****"/> <br/>

时间:2011-04-03 17:27:33

标签: php regex

您好如何在每场比赛结束时添加<img src=*****><br>但没有数组,因为我会对结果进行编码?

preg_match_all('!http://.+\.(?:jpe?g|png|gif)!Ui', $content, $filtered);

2 个答案:

答案 0 :(得分:0)

只需连接结果并将它们存储在数组中:

$arr = array();
$arr[] = $filtered[0] . "<br/>";

答案 1 :(得分:0)

if(preg_match_all('#http://[\S]+(?:jpe?g|png|gif)#is', $html, $matches)){
$i = 0;
foreach($matches[0] as $value){
    if(in_array($i, array(0, 3))) continue;
    $img .= '<img src="'.$value.'"><br>';
    $i++;
    }
}

echo $img;

输出(手动删除域名)

<img src="http://galerije/ford%20focus/qy974l.jpg"><br><img src="http://galerije/ford%20focus/m8zhh0.jpg"><br><img src="http://galerije/ford%20focus/ifpixx.jpg"><br><img src="http://galerije/ford%20focus/1zvzof8.jpg"><br><img src="http://galerije/ford%20focus/ir8cqv.jpg"><br><img src="http://galerije/ford%20focus/9vjtrd.jpg"><br><img src="http://galerije/ford%20focus/2m29p4j.jpg"><br><img src="http://galerije/ford%20focus/znm0yt.jpg"><br><img src="http://galerije/ford%20focus/2ln8l7t.jpg"><br><img src="http://galerije/ford%20focus/mta0ap.jpg"><br>