2014-02-07 29 views
0

我從我的數據庫中獲取了一些數據。我只想從iframe中打印url。如何從Iframe中選擇任何網址

我的數據:

$data="<p style="text-align: justify;">Este foi o anúncio que a Microsoft passou no dia da Super Bowl. Veja como a tecnologia têm melhorado a vida das pessoas.</p> 

<div class="fluid-width-video-wrapper"> 
<iframe width="640" height="400" src="//www.youtube.com/embed/qaOvHKG0Tio" frameborder="0" allowfullscreen></iframe> 
</div>"; 
+1

是什麼問題? –

+0

我只想從$ data @SatishSharma – shanto

+0

只顯示www.youtube.com/embed/qaOvHKG0Tio我想在你的'$ data'變量中只提取src。我對嗎? –

回答

1

這裏是你的答案

你應該提取substring$data變量這樣

$data='<p style="text-align: justify;">Este foi o anúncio que a Microsoft passou no dia da Super Bowl. Veja como a tecnologia têm melhorado a vida das pessoas.</p> 

<div class="fluid-width-video-wrapper"> 
<iframe width="640" height="400" src="//www.youtube.com/embed/qaOvHKG0Tio" frameborder="0" allowfullscreen></iframe> 
</div>'; 

$from = 'src="'; 
$to = '"'; 
$str = getStringBetween($data,$from,$to); 
echo $str; // will output : //www.youtube.com/embed/qaOvHKG0Tio 

功能

function getStringBetween($str,$from,$to) 
    { 
     $sub = substr($str, strpos($str,$from)+strlen($from),strlen($str)); 
     return substr($sub,0,strpos($sub,$to)); 
    }