ȸ¿ø°¡ÀԡžÆÀ̵ð/ºñ¹øã±â
ȨÀ¸·Î


À¯Åõºê µ¿¿µÀå ÁÖ¼Ò ÃßÃâ Á¤±Ô½Ä ¿¹ 1
10³â Àü
A YouTube video URL may be encountered in a variety of formats:
latest short format: http://youtu.be/NLqAF9hrVbY
iframe: http://www.youtube.com/embed/NLqAF9hrVbY
iframe (secure): https://www.youtube.com/embed/NLqAF9hrVbY
object param: http://www.youtube.com/v/NLqAF9hrVbY?fs=1&hl=en_US
object embed: http://www.youtube.com/v/NLqAF9hrVbY?fs=1&hl=en_US
watch: http://www.youtube.com/watch?v=NLqAF9hrVbY
users: http://www.youtube.com/user/Scobleizer#p/u/1/1p3vcRhsYGo
ytscreeningroom: http://www.youtube.com/ytscreeningroom?v=NRHVzbJVx8I
any/thing/goes!: http://www.youtube.com/sandalsResorts#p/c/54B8C800269D7C1B/2/PPS-8DMrAn4
any/subdomain/too: http://gdata.youtube.com/feeds/api/videos/NLqAF9hrVbY
more params: http://www.youtube.com/watch?v=spDj54kf-vY&feature=g-vrec

Here is a PHP function with a commented regex that matches each of these URL forms and converts them to links (if they are not links already):
// Linkify youtube URLs which are not already links.function linkifyYouTubeURLs($text) {    $text = preg_replace('~
        # Match non-linked youtube URL in the wild. (Rev:20111012)
        https?://         # Required scheme. Either http or https.
        (?:[0-9A-Z-]+\.)? # Optional subdomain.
        (?:               # Group host alternatives.
          youtu\.be/      # Either youtu.be,
        | youtube\.com    # or youtube.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">YouTube link: $1</a>',        $text);    return $text;}

And Here is a JavaScript version with the exact same regex (with comments removed):
// Linkify youtube URLs which are not already links.function linkifyYouTubeURLs(text) {    var re = /https?:\/\/(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube\.com\S*[^\w\-\s])([\w\-]{11})(?=[^\w\-]|$)(?![?=&+%\w]*(?:['"][^<>]*>|<\/a>))[?=&+%\w-]*/ig;    return text.replace(re,        '<a href="http://www.youtube.com/watch?v=$1">YouTube link: $1</a>');}

Notes:
The VIDEO_ID portion of the URL is captured in the one and only capture group: $1.
If you know that your text does not contain any pre-linked URLs, you can safely remove the negative lookahead assertion which tests for this condition (The assertion beginning with the comment:"Assert URL is not pre-linked.") This will speed up the regex somewhat.
The replace string can be modified to suit. The one provided above simply creates a link to the generic "http://www.youtube.com/watch?v=VIDEO_ID" style URL and sets the link text to:"YouTube link: VIDEO_ID".

ÃßõÃßõ : 388 Ãßõ ¸ñ·Ï
¹øÈ£ Á¦¸ñ
223
Á¤±Ô½Ä ÆÁ
222
±×´©º¸µå¿¡¼­ »ç¿ëµÈ XSS (Cross Site Script) ¸·±â
221
À¯Åõºê µ¿¿µÀå ÁÖ¼Ò ÃßÃâ PHP Á¤±Ô½Ä ¿¹ 2 (parse_str ¹æ½Ä)
À¯Åõºê µ¿¿µÀå ÁÖ¼Ò ÃßÃâ Á¤±Ô½Ä ¿¹ 1
219
YouTube shortcode fix for a blog imported from WordPress.com
218
PHP < ![CDATA[ 2 ]]> Á¦°Å Á¤±Ô½Ä
217
span, font ű׸¦ Á¦°ÅÇÏ´Â Á¤±Ô½Ä
216
º»¹®¿¡¼­ À̹ÌÁö ÃßÃâ, À̹ÌÁö Á¦°Å Á¤±Ô½Ä
215
¿©·¯°³ÀÇ ºóÄ­ , ÁÙÀ» °ø¹éÀ¸·Î º¯°æÇϱâ
214
URL ó¸® °ü·Ã Á¤±Ô½Ä
213
PHP Á¤±Ô½Ä À¯È¿¼º°Ë»ç ¿¹Á¦ (IDüũ, À̸ÞÀÏüũµî)
212
PHP¿¡¼­ Ư¼ö¹®ÀÚ ¾ø¾Ö´Â Á¤±ÔÇ¥Çö½Ä
211
php ¹®ÀÚ¿­ ÀÚ¸£±â, ºñ±³, ã±â ÇÔ¼ö, str_replace, substr ,strpos, explode µîµî Á¤¸®
210
¼¼¼Ç ¹× ÄíÅ°ÀÇ Á¤º¸¸¦ ¾ÏȣȭÇϱâ
209
GetImageSize À̹ÌÁöÆÄÀÏÀÇ »çÀÌÁ ¾Ë¾Æ³»´Â ÇÔ¼ö
208
¹®ÀÚ¿­ÀÇ °ø¹éÀ» À߶󳻴 chop, trim, ltrim ÇÔ¼ö
207
µÎ°³ÀÇ º¯¼ö¸¦ ºñ±³ÇÏ´Â strcmp ÇÔ¼ö
206
ű׸¦ ¾ø¾Ö°í Ãâ·ÂÇÏ´Â strip_tags ÇÔ¼ö
205
ű׸¦ ±×´ë·Î Ãâ·ÂÇÏ´Â htmlspecialchars ÇÔ¼ö
204
º¯¼ö³»¿¡ ¿ª½½·¡½Ã ³Ö±â¿Í »©±â
203
Á¦¾î ±¸Á¶ÀÇ ´ëü ¹®¹ý
202
elseif/else if
201
if..endif ±¸¹®
200
POST, GETÀ¸·Î º¯¼ö°ªÀÌ ³Ñ¾î°¡Áö ¾Ê´Â °æ¿ì - register_globals
199
PHP ÆÄÀÏ°ü·Ã ÇÔ¼ö
198
¿ø°ÝÁö ÆÄÀÏÀÇ Á¸Àç ¿©ºÎ¸¦ üũ »ç¿ëÀÚ ÇÔ¼ö
197
PHP ÆÄÀÏ ´Ù·ç±â
196
[PHP] ÆÄÀÏ ÇÔ¼ö
195
ÆÄÀÏ »ý¼º, ±â·Ï, Àбâ
194
´Ù¸¥ ¼­¹ö·Î °ªÀ» Àü¼ÛÈÄ °á°ú°ªÀ» ¹Þ´Â ¹æ¹ý
¸ñ·Ï
¹ÂÁ÷Æ®·ÎÆ® ºÎ»ê±¤¿ª½Ã ºÎ»êÁø±¸ °¡¾ßµ¿ ¤Ó °³ÀÎÁ¤º¸Ãë±Þ¹æħ
Copyright ¨Ï musictrot All rights reserved.