我有一个这样的字符串:
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, https://www.youtube.com/watch?v=7TL02DA5MZM when an unknown printer took a galley of type and scrambled it to make a type
这就是我所拥有的:
preg_match("(?:http://)?(?:www.)?(?:youtube.com|youtu.be)/(?:watch\?)?([^\s]+?)", $content, $m);
var_dump( $m );
并想从中提取 youtube 链接。
视频 ID 也可以。
不胜感激!
这对你有用,
\S*\bwww\.youtube\.com\S*
\S*
匹配零个或多个非空格字符。
代码是,
preg_match('~\S*\bwww\.youtube\.com\S*~', $str, $matches);
DEMO
我对你原来的正则表达式做了一些更正。
(?:https?://)?(?:www.)?(?:youtube.com|youtu.be)/(?:watch\?v=)?([^\s]+)
DEMO
$str = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, https://www.youtube.com/watch?v=7TL02DA5MZM when an unknown printer took a galley of type and scrambled it to make a type";
preg_match('~(?:https?://)?(?:www.)?(?:youtube.com|youtu.be)/(?:watch\?v=)?([^\s]+)~', $str, $match);
print_r($match);
Output:
Array
(
[0] => https://www.youtube.com/watch?v=7TL02DA5MZM
[1] => 7TL02DA5MZM
)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)