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
Post a Comment