Add a <img src=*****><br> at the end of this regular expression
Hello how can I add a <img src=*****><br>
at the end of every match but without array because I 开发者_如何学Pythonwill encode the results?
preg_match_all('!http://.+\.(?:jpe?g|png|gif)!Ui', $content, $filtered);
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;
Output (removed domain name by hand)
<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>
Just concatenate the results and store them in an array:
$arr = array();
$arr[] = $filtered[0] . "<br/>";
精彩评论