2017-06-19 48 views
0

我需要獲取圖像的一些幫助。我使用preg_match_all函數。我如何使用preg_match_all獲取圖像

來源:<img alt="test" title="test" src="/data/brands/test.png">

我怎樣才能得到完整的圖像網址?

這是我的文本代碼。我需要在這裏添加圖片。

<? 
$link = 'link'; 
$marka = '@<div class="test">(.*?)</div>@si'; 
$getir = file_get_contents($link); 

preg_match_all($marka,$getir,$test1); 

$test = $test1[0]; 

echo $test[0]; ?> 

謝謝。

回答

0

這可以幫助你

$str = '<img alt="test" title="test" src="/data/brands/test.png">'; 

$regex = '#src="(.+?)">#'; 

preg_match($regex,$str,$match); 

echo $match[1]; 

//prints: /data/brands/test.png 
+0

這至少是一個語法錯誤 –

+0

下一步 - 它將從''