你可以在雙引號用正則表達式分割字符串。
$re = '/\<iframe[^\>]+src\="(.+?)\/([A-Za-z0-9]+)"/';
$str = '<iframe src="https://www.example.com/embed/ph57d6z9fa1349b" frameborder="0" height="481" width="608" scrolling="no"></iframe>';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
如果要列出ID碼(如 'ph57d6z9fa1349b'),那麼你可以這樣做:
<?php
$re = '/\<iframe[^\>]+src\="(.+?)\/([A-Za-z0-9]+)"/';
$str = '<iframe src="https://www.example.com/embed/ph57d6z9fa1349b" frameborder="0" height="481" width="608" scrolling="no"></iframe>';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
foreach ($matches as $match) {
$id = $match[2]; // The required id code
echo $id; // Echo it
}
?>
這是大材小用? [https://3v4l.org/v01sD](https://3v4l.org/v01sD)。的xD – FirstOne