【发布时间】:2014-01-30 06:49:15
【问题描述】:
$article = ('<p>In show business it is all about the extremes. For example the people
below earn a whole load of money thanks to their appearance and it is not at all
beautiful. They are some of the ugliest models but nevertheless they still work in
full swing. They get hired in movies, commercials, and anywhere where an ugly guy
(or a girl) is needed , and if you’re just plane average and you still wish to
work, well then you should probably do something extreme with your body like the
lizard man, for example.</p></a>
<a href="http://www.youtube.com/watch?v=eauCiY1MmZU">
http://www.youtube.com/watch?v=eauCiY1MmZU
</a>
function tubeCodeEmbed( $vCode ) {
return $vCode;
}
$search = '/\s*[a-zA-Z\/\/:\.]*youtube.com\/watch\?v=([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i';
$article = preg_replace($search, tubeCodeEmbed("$1"), $article);
echo $article;
这是我到目前为止所拥有的......它可以工作,只是它不会从包含 youtube 的字符串中删除 href。
我想要的输出
在演艺界,一切都是关于极端的。例如人们 由于他们的外表,下面赚了一大笔钱 一点都不漂亮。 joeCiY1MmZU 他们是最丑的模特 但尽管如此,他们仍然如火如荼地工作。他们被录用 电影、广告以及任何有丑男(或女孩)的地方 需要,如果你只是平庸而你仍然想工作, 那么你可能应该对你的身体做一些极端的事情,比如 例如蜥蜴人。奇数CiY1MmZU eauCiY1MmZU
注意输出中的 ID ...没有来自 youtube 的 url 或 href 标签
【问题讨论】:
-
我试过了……它不能满足我的需要。
-
@JosephPhilbert,你能用你问的
output编辑你的问题吗? -
我需要删除 youtube 链接/主机的“HREF”标签。
-
试试这个 '$html = preg_replace_callback("/(?([^/", '', $html);函数 parseID($matches){ if (preg_match("%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?: mbed)?)/|.*[?&]v=)|youtu\.be/)([^\"&?/ ]{11})%i", $matches[0], $match)) { $video_id = $match[1]; // 这里是视频 id } } echo $final;'