Skip to content

Instantly share code, notes, and snippets.

@vaporic
Forked from lenivene/readme.md
Created November 24, 2017 17:59
Show Gist options
  • Select an option

  • Save vaporic/7fdd2ff5b99f56f5bbe4b72f7b9d4cba to your computer and use it in GitHub Desktop.

Select an option

Save vaporic/7fdd2ff5b99f56f5bbe4b72f7b9d4cba to your computer and use it in GitHub Desktop.

Revisions

  1. @lenivene lenivene revised this gist Sep 8, 2016. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,9 @@
    # Example code
    ```php
    <?php
    $link = "https://www.youtube.com/watch?v=sOnqjkJTMaA";
    $youtube_ID = get_youtube_ID( $link );

    echo $youtube_ID;
    ?>
    ```

    ```html
  2. @lenivene lenivene revised this gist Sep 8, 2016. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,13 @@
    # Example code
    ```php
    <?php
    $link = "https://www.youtube.com/watch?v=sOnqjkJTMaA";
    $youtube_ID = get_youtube_ID( $link );

    echo $youtube_ID;
    ?>
    ```

    ```html
    <iframe width="560" height="315" src="https://www.youtube.com/embed/<?php echo $youtube_ID; ?>" frameborder="0" allowfullscreen></iframe>

    ```
  3. @lenivene lenivene revised this gist Sep 6, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -5,4 +5,6 @@ $youtube_ID = get_youtube_ID( $link );

    echo $youtube_ID;

    <iframe width="560" height="315" src="https://www.youtube.com/embed/<?php echo $youtube_ID; ?>" frameborder="0" allowfullscreen></iframe>

    ```
  4. @lenivene lenivene revised this gist Sep 6, 2016. 2 changed files with 19 additions and 2 deletions.
    8 changes: 8 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    # Example code
    ```php
    $link = "https://www.youtube.com/watch?v=sOnqjkJTMaA";
    $youtube_ID = get_youtube_ID( $link );

    echo $youtube_ID;

    ```
    13 changes: 11 additions & 2 deletions youtube.id.php
    Original file line number Diff line number Diff line change
    @@ -5,5 +5,14 @@
    * @var string $link [ https, m., gaming., www., youtube.com gaming.youtube.com, youtu.be ]
    * @return array $youtube URL && ID
    */
    $link = ''; // url here
    preg_match( '/(?:https?:\/\/|www\.|gaming\.|m\.|^)youtu(?:be\.com\/watch\?(?:.*?&(?:amp;)?)?v=|\.be\/)([\w‌​\-]+)(?:&(?:amp;)?[\w\?=]*)?/', $link, $youtube );

    function get_youtube_ID( $link ){
    if( !isset( $link ) || empty( $link ) )
    return;

    preg_match( '/(?:https?:\/\/|www\.|gaming\.|m\.|^)youtu(?:be\.com\/watch\?(?:.*?&(?:amp;)?)?v=|\.be\/)([\w‌​\-]+)(?:&(?:amp;)?[\w\?=]*)?/', $link, $ID );

    $YouTube_ID = isset( $ID[1] ) ? $ID[1] : false;

    return $YouTube_ID;
    }
  5. @lenivene lenivene created this gist Jul 22, 2016.
    9 changes: 9 additions & 0 deletions youtube.id.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    <?php
    /**
    * Get YouTube url ID
    *
    * @var string $link [ https, m., gaming., www., youtube.com gaming.youtube.com, youtu.be ]
    * @return array $youtube URL && ID
    */
    $link = ''; // url here
    preg_match( '/(?:https?:\/\/|www\.|gaming\.|m\.|^)youtu(?:be\.com\/watch\?(?:.*?&(?:amp;)?)?v=|\.be\/)([\w‌​\-]+)(?:&(?:amp;)?[\w\?=]*)?/', $link, $youtube );