2011-11-05 64 views
0

我有以下代码:str_replace与随机值?

$embed_url = str_replace('<iframe width="512" height="288" frameborder="0" scrolling="no" src="', '', $embed_url); 
    $embed_url = str_replace('"></iframe>', '', $embed_url); 

会发生什么事是iframe的宽度和高度是不固定的值,因此它们可以是任何其他数字。

我怎样才能使此作品的任何宽度/高度?

谢谢。

编辑:我想要得到的是src值。

回答

2

你可以使用正则表达式:如果你想要的是检索的src

$embed_url = preg_replace('/<iframe width=".*?" height=".*?" frameborder="0" scrolling="no" src="/', '', $embed_url); 

,你可以使用preg_match()代替:

if (preg_match('/<iframe.*?src="(.+?)"/ms', $embed_url, $matches)) { 
    $src = $matches[1]; 
} 
+0

Tha是完美的。泰! – PGZ

1

你会使用

$embed_url = preg_replace('!<iframe width="[0-9]+?" height="[0-9]+?" frameborder="0" scrolling="no" src="!','',$embed_content); 
0

代替使用str_replace,只需使用bu以价值取代为例:

$width = '512'; 
$height = '288'; 

$iframe = '<iframe width="$width" height="$height" frameborder="0" scrolling="no" src="$embed_url"></iframe>'; 

HTH。