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


À¯Åõºê µ¿¿µÀå ÁÖ¼Ò ÃßÃâ Á¤±Ô½Ä ¿¹ 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 Ãßõ ¸ñ·Ï
¹øÈ£ Á¦¸ñ
2,495
Ư¼ö¹®ÀÚ ¾ø¾Ö´Â Á¤±ÔÇ¥Çö½Ä / pcre ·Î °£´ÜÈ÷ ´Ü¾î¸¸ ÃßÃâÇϱâ
2,494
http://www.gskinner.com/RegExr/ Á¤±Ô½Ä Å×½ºÆ® »çÀÌÆ®
2,493
PCRE Á¤±ÔÇ¥Çö½Ä ¿¹Á¦·Î °³³äÀâ±â.
2,492
page º¯¼ö Áߺ¹ Á¦°Å ÆäÀÌ¡ ó¸® &page= Á¦°Å
2,491
Ư¼ö¹®ÀÚ ¾ø¾Ö´Â Á¤±ÔÇ¥Çö½Ä
2,490
regex Á¤±Ô½Ä ¿¹Á¦
2,489
ereg / eregi ¿À·ù Function eregi() is deprecated in ó¸®
2,488
phpÇѱÛüũ¸¦ À§ÇÑ Á¤±ÔÇ¥Çö½Ä
2,487
Á¤±Ô½Ä ¹®ÀÚ¿­ ³» À̹ÌÁö,¸µÅ© ÃßÃâÇϱâ
2,486
Á¤±Ô½Ä ¹è¿­·Î ¿©·¯ °³ µ¿½Ã ó¸®
2,485
{include ÆÄÀϸí.php} ó¸® (ÆÄÀϸí ġȯ ó¸®)
2,484
³»¿ëÁß image ÃßÃâ ó¸®
2,483
¹øÈ£ ½ÃÀÛ 1. tets 2.tets 11.test ÃßÃâ Á¤·Ä ó¸®
2,482
¹®ÀÚ¿­¿¡¼­ ¿µ¹®+¼ýÀÚ¸¸ÃßÃâÇϱâ
2,481
¿µ¹®Àڷθ¸ µÇ¾î ÀÖ´ÂÁö
2,480
php Á¤±Ô½Ä Á¾·ùº° ¹®ÀÚ ÃßÃâ
2,479
preg_match °Ë»ö´ë»ó¿¡ ¿£ÅÍ°¡ µé¾î°£°æ¿ì´Â °Ë»ö¿É¼Ç¿¡ s ¸¦ Ãß°¡Ç϶ó.
2,478
Á¤±Ô½Ä, Ư¼ö¹®ÀÚ ÀÔ·Â Á¦ÇÑ
2,477
Á¤±Ô½Ä Ư¼ö¹®ÀÚ PHP
2,476
PHP¿¡¼­ Ư¼ö¹®ÀÚ ¾ø¾Ö´Â Á¤±ÔÇ¥Çö½Ä
2,475
2013-06-05 (¼ö) 19:30 ¸¦ Ç¥ÁØ ³¯Â¥·Î º¯°æÇϱâ
2,474
Á¤±Ô½Ä 1Â÷ µµ¸ÞÀθ¸ ÃßÃâ
2,473
Á¤±ÔÇ¥Çö½ÄÀ» ÀÌ¿ëÇÑ ÆäÀÌÁöÆÄ½Ì ¿¹Á¦ Ãâó:À¯Ã¢È­´Ô ºí·Î±×
2,472
³¯Â¥ 2013-12-31 ¿¡¼­ ³¯Â¥ ¿ù Àбâ Á¤±Ô½Ä
2,471
Á¤±Ô½Ä ÆÁ
2,470
±×´©º¸µå¿¡¼­ »ç¿ëµÈ XSS (Cross Site Script) ¸·±â
2,469
À¯Åõºê µ¿¿µÀå ÁÖ¼Ò ÃßÃâ PHP Á¤±Ô½Ä ¿¹ 2 (parse_str ¹æ½Ä)
À¯Åõºê µ¿¿µÀå ÁÖ¼Ò ÃßÃâ Á¤±Ô½Ä ¿¹ 1
2,467
YouTube shortcode fix for a blog imported from WordPress.com
2,466
PHP < ![CDATA[ 2 ]]> Á¦°Å Á¤±Ô½Ä
¸ñ·Ï
¹ÂÁ÷Æ®·ÎÆ® ºÎ»ê±¤¿ª½Ã ºÎ»êÁø±¸ °¡¾ßµ¿ ¤Ó °³ÀÎÁ¤º¸Ãë±Þ¹æħ
Copyright ¨Ï musictrot All rights reserved.