I am attempting to use PHP to trim a YouTube URL lower towards the video ID. It's working, but it is also adding lots of whitespace towards the result. Does anybody understand how I'd have the ability to fix this? Here's the setup:

Situated in Wordpress single.php (finds attached YouTube URL from publish meta):

<?php   
$vidurl = get_post_meta($post->ID, "_videoembed", true );
$youtube_id = getYouTubeIdFromURL($vidurl);
echo $youtube_id;          
?>

Here's what's performing the function:

//Get YT Video ID
function getYouTubeIdFromURL($url)
{
  $url_string = parse_url($url, PHP_URL_QUERY);
  parse_str($url_string, $args);
  return isset($args['v']) ? $args['v'] : false;
}

Like I stated, the function works fine, however it produces a lot of whitened space. The video incorporated within the meta is youtube.com/watch?v=1337&feature=player_embedded it'll return

"                1337    "

I appreciate all help ahead of time! I have had some great people assist me to on this website before.

Are you certain your get_post_meta function is not coming back a lot of spaces by using it? Are you able to perform a var_dump on $vidurl? After I run the function you gave, the output looks all right (http://www.ideone.com/LRoTd):

<?php
    function getYouTubeIdFromURL($url)
    {
        $url_string = parse_url($url, PHP_URL_QUERY);
        parse_str($url_string, $args);
        return isset($args['v']) ? $args['v'] : false;
    }

    $theurl = "youtube.com/watch?v=1337&feature=player_embedded";
    $youtubeid = getYouTubeIdFromURL($theurl);
    echo "'$youtubeid'";
?>

Output:

'1337'