2012-04-30 6 views
0

離れトリムIはU字管からのiframeするMySQLデータベースの次のデータを有する: -PHP望ましくないテキスト

`<iframe width="560" height="315" src="http://www.youtube.com/embed/Om2fabTIKE4" frameborder="0" allowfullscreen></iframe>` 

はそれにもかかわらず、PHPコードでは、現在の位相は、上記IFRAMEのために存在します変数を充填することとしてここで私はちょうどOm2fabTIKE4を必要としています。

I would like to ask, is there any way that I can trim away 

<iframe width="560" height="315" src="http://www.youtube.com/embed/

frameborder="0" allowfullscreen></iframe>

+0

は、preg_replace()、preg_match()の仕事のように聞こえます。 –

答えて

0

使用str_replaceこのお試しくださいテキスト

+0

は動作します。しかし、私は、u-tubeのiframeがwidth = "420" height = "315"のとき、str_replaceが機能しなくなることを認識しています。文字列の長さを認識したり、 " Ham

+0

単純な方法は、 '560'のために2回、' 420'のためにもう一度それを実行して、正規表現をチェックアウトします。文字列の長さを取得するには、[strlen](http://php.net/manual/en/function.strlen.php)を使用してください。区切り文字 'embed /'で文字列を[explode](http://php.net/manual/en/function.explode.php)することもできます。 – anselm

2

を削除する:あなたはDOMDocument class hereについての詳細を学ぶことができ

$html = '<iframe width="560" height="315" src="http://www.youtube.com/embed/Om2fabTIKE4" frameborder="0" allowfullscreen></iframe>'; 
$dom = new DOMDocument();                   
$dom->loadHTML($html);                    
$tags = $dom->getElementsByTagName('iframe');              
foreach ($tags as $tag)                    
    $link = explode('/',parse_url($tag->getAttribute('src'),PHP_URL_PATH));       
var_dump($link[2]);  

を。

関連する問題