0

I have the following string as a PHP variable.

<div class="entry-content-asset">
     <div class="embed">
      <iframe width="500" height="281" src="https://www.youtube.com/embed/DSP_yxvRZOA?feature=oembed" frameborder="0" allowfullscreen></iframe>
    </div>
</div>

I need to programatically search this string and find only the Video ID DSP_yxvRZOA

The string is the same every time save for the youtube video id. I am terrible at writing regular expressions, can anyone save me?

Nacimota
  • 22,395
  • 6
  • 42
  • 44
Nicholas Koskowski
  • 793
  • 1
  • 4
  • 23

1 Answers1

2

Assuming your string is named $str:

$re = '/embed\/(.*)\?feature/';
preg_match_all($re, $str, $matches);

Will match anything between embed/ and ?feature and put it into the first capturing group.

bejado
  • 1,430
  • 12
  • 19