Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am making slight changes in the above regular expression, although it is working fine for youtube short URL (which have been used in the above example) and simple video URL where no other parameter is coming after video code, but it does not work for URLs like <a href="http://www.youtube.com/watch?v=B_izAKQ0WqQ&amp;feature=related" rel="noreferrer">http://www.youtube.com/watch?v=B_izAKQ0WqQ&amp;feature=related</a> as video code is not the last parameter in this URL. In the same way v={video_code} does not always come after watch (whereas above regular expression is assuming that it will always come after watch?), like if user has selected language OR location from the footer, for example if user has selected English (UK) from Language option then URL will be <a href="http://www.youtube.com/watch?feature=related&amp;hl=en-GB&amp;v=B_izAKQ0WqQ" rel="noreferrer">http://www.youtube.com/watch?feature=related&amp;hl=en-GB&amp;v=B_izAKQ0WqQ</a> </p> <p>So I have made some modification in the above regular expressions, but definitely credit goes to hakre for providing the base regular expression, thanks @hakre:</p> <pre><code>function youtube_id_from_url($url) { $pattern = '%^# Match any youtube URL (?:https?://)? # Optional scheme. Either http or https (?:www\.)? # Optional www subdomain (?: # Group host alternatives youtu\.be/ # Either youtu.be, | youtube\.com # or youtube.com (?: # Group path alternatives /embed/ # Either /embed/ | /v/ # or /v/ | .*v= # or /watch\?v= ) # End path alternatives. ) # End host alternatives. ([\w-]{10,12}) # Allow 10-12 for 11 char youtube id. ($|&amp;).* # if additional parameters are also in query string after video id. $%x' ; $result = preg_match($pattern, $url, $matches); if (false !== $result) { return $matches[1]; } return false; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload