$str = '<iframe src="https://www.google.com/maps/place/the-big-junky-map-url-with-lat-lon-etc-etc" width="100%" height="350" frameborder="0" style="border:0;" allowfullscreen></iframe>';
$matches = array();
preg_match('/src\=\"((.*?))\"/i',$map, $matches);
echo '<pre>';print_r($matches);die();
我想從src
屬性中提取URL。我在$matches
。preg_match - 爲什麼兩個相同的項目匹配
Array
(
[0] => src="https://www.google.com/maps/place/the-big-junky-map-url-with-lat-lon-etc-etc"
[1] => https://www.google.com/maps/place/the-big-junky-map-url-with-lat-lon-etc-etc
[2] => https://www.google.com/maps/place/the-big-junky-map-url-with-lat-lon-etc-etc
)
我得到了我所需要的,但爲什麼有兩個相同的[1] [2]?我怎樣才能避免這種情況?
'((。*?))'2個捕獲組== 2個結果的要素 – Rizier123
你應該使用'$ str' '$ map'。 –
@ Rizier123,你對了 –