我需要什么如何解析你管的代码在php
我需要应该在你管的URL追加11位数字代码。
like www.youtube.com/embed/XzqagJTsNrc.
源代码
$url= htmlentities($this->linkify($row['tweetText']));
$youtube=explode(' ',$url).
阵列输出。
Array
(
[0] => VW
[1] => @
[2] => European
[3] => Motor
[4] => Show
[5] => Brussels
[6] => -
[7] => Behind
[8] => the
[9] => scene
[10] => (part
[11] => 1):
[12] => &nbsp;<a
[13] => class="twtlnk"
[14] => rel="nofollow"
[15] => href="http://youtu.be/XzqagJTsNrc"
[16] => target=\"_blank\">http://youtu.be/XzqagJTsNrc</a>
[17] => via
[18] => &nbsp;<a
[19] => class="twthand"
[20] => href="https://twitter.com/youtube"
[21] => rel="nofollow"
[22] => target=\"_blank\"
[23] => >@youtube</a>
)
我已使用正则表达式
$text = preg_replace('~
https?:// # Required scheme. Either http or https.
(?:[0-9A-Z-]+\.)? # Optional subdomain.
(?: # Group host alternatives.
youtu\.be/ # Either youtu.be,
| youtube # or youtube.com or
(?:-nocookie)? # youtube-nocookie.com
\.com # followed by
\S* # Allow anything up to VIDEO_ID,
[^\w\s-] # but char before ID is non-ID char.
) # End host alternatives.
([\w-]{11}) # $1: VIDEO_ID is exactly 11 chars.
(?=[^\w-]|$) # Assert next char is non-ID or EOS.
(?! # Assert URL is not pre-linked.
[?=&+%\w.-]* # Allow URL (query) remainder.
(?: # Group pre-linked alternatives.
[\'"][^<>]*> # Either inside a start tag,
| </a> # or inside <a> element text contents.
) # End recognized pre-linked alts.
) # End negative lookahead assertion.
[?=&+%\w.-]* # Consume any URL (query) remainder.
~ix',
'<a href="http://www.youtube.com/watch?v=$1">$1</a>',
$youtube);
print_r($text);
阵列返回
Array
(
[0] => VW
[1] => @
[2] => European
[3] => Motor
[4] => Show
[5] => Brussels
[6] => -
[7] => Behind
[8] => the
[9] => scene
[10] => (part
[11] => 1):
[12] => &nbsp;<a
[13] => class="twtlnk"
[14] => rel="nofollow"
[15] => href="<a href="http://www.youtube.com/watch?v=XzqagJTsNrc">XzqagJTsNrc</a>;
[16] => target=\"_blank\"><a href="http://www.youtube.com/watch?v=XzqagJTsNrc">XzqagJTsNrc</a>;/a>
[17] => via
[18] => &nbsp;<a
[19] => class="twthand"
[20] => href="https://twitter.com/youtube"
[21] => rel="nofollow"
[22] => target=\"_blank\"
[23] => >@youtube</a>
)试图
- 我只需要获取XzqagJTsNrc;在做print_r($ text [15]);
- 它输出的href =“XzqagJTsNrc;
,但我只需要XzqagJTsNrc(11位字符内)
how to parse href="XzqagJTsNrc; (href =" ;)
我也问过HREF =“XzqagJTsNrc;如何删除href =“和;从代码 – user2818060 2014-10-09 07:37:07
这意味着解析youtube代码,如果你删除'href =”'和';'只有youtube代码是:) – Saqueib 2014-10-09 07:48:16
是我想要的 – user2818060 2014-10-09 07:49:17