Obtener ID de video de YouTube desde URL con PHP

Estoy tratando de crear una función que invoque un valor desde un campo personalizado de Wordpress ("_videourl" para una URL de video de YouTube) y luego use el recorte de PHP para reducirlo solo a la ID de video de YouTube. Encontré una función de JavaScript que reduce las URL solo a la ID, pero no tengo idea de cómo podría traducir eso a php (función a continuación):

     function youtubeIDextract(url) 
     { 
     var youtube_id; 
     youtube_id = url.replace(/^[^v]+v.(.{11}).*/,"$1"); 
     return youtube_id; 
     }

Esta función PHP se usaría dentro del bucle, así que yopensa Tendría que usar variables, pero realmente soy un novato, así que no tengo idea de qué hacer. ¿Alguien puede ayudar compartiendo su experiencia en codificación para ayudarme a crear una función PHP?

EDIT: RESUELTO

Después de experimentar un poco, encontré una solución. Quería regresar y publicarlo para que otros también necesitados tuvieran un lugar desde donde comenzar.

function getYoutubeId($ytURL) 
    {
        $urlData = parse_url($ytURL);
        //echo '<br>'.$urlData["host"].'<br>';
        if($urlData["host"] == 'www.youtube.com') // Check for valid youtube url
        {
            $ytvIDlen = 11; // This is the length of YouTube's video IDs

            // The ID string starts after "v=", which is usually right after 
            // "youtube.com/watch?" in the URL
            $idStarts = strpos($ytURL, "?v=");

            // In case the "v=" is NOT right after the "?" (not likely, but I like to keep my 
            // bases covered), it will be after an "&":
            if($idStarts === FALSE)
                $idStarts = strpos($ytURL, "&v=");
            // If still FALSE, URL doesn't have a vid ID
            if($idStarts === FALSE)
                die("YouTube video ID not found. Please double-check your URL.");

            // Offset the start location to match the beginning of the ID string
            $idStarts +=3;

            // Get the ID string and return it
            $ytvID = substr($ytURL, $idStarts, $ytvIDlen);

            return $ytvID;
        }
        else
        {
            //echo 'This is not a valid youtube video url. Please, give a valid url...';
            return 0;
        }

    } 

Respuestas a la pregunta(2)

Su respuesta a la pregunta