regex - Use PHP to extract specific string data -


the iframe assigned variable $string. want extract texts between embed/ , ?rel in iframes src. looking code sl-2oyai35o

<iframe width="420" height="315" src="http://www.youtube.com/embed/sl-2oyai35o?rel=0" frameborder="0" allowfullscreen></iframe> 

would need use php substr function or regex? cant use regular substring because start value may differ.

$text = '<iframe width="420" height="315" src="http://www.youtube.com/embed/sl-2oyai35o?rel=0" frameborder="0" allowfullscreen></iframe>';  preg_match('`embed/(.+)\?rel`i', $text, $matches); $code = (!empty($matches[1])) ? $matches[1] : ''; 

Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -