Taking only the attribute "src"

Asked

Viewed 60 times

0

within my system, it should take only the attribute "src" from within a variable and put into a new, follow the example:

//<iframe class="embed-responsive-item" src="https://www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2Funiladmag%2Fvideos%2F4623781360978220%2F&show_text=0&width=476" width="476" height="476" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true" allowFullScreen="true"></iframe>
$iFrame = $_POST['vid_iframe'];

How would I get only what’s inside the "src"? I tried to use a explode but it didn’t work.

  • Using jQuery, you can do $('.embed-responsive-item').attr('src') and retrieve the iframe attribute.

1 answer

1


if it’s php and your string is iframe does so

$variavel='<iframe class="embed-responsive-item" src="https://www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2Funiladmag%2Fvideos%2F4623781360978220%2F&show_text=0&width=476" width="476" height="476" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true" allowFullScreen="true"></iframe>';

$var=explode('src="',$variavel);
$var=explode('"',$var['1']);
echo $var['0'];

Browser other questions tagged

You are not signed in. Login or sign up in order to post.