PHP: Array comparison issue- URLs
<p>I have put together php code that will notify if a YT video is valid or invalid. Since I only want URLs from the YT domain I have set an array to catch any other URL case and return an error. The problem is that when I type a URL in a format like: <code>www.youtube.com/v/NLqAF9hrVbY</code> i get the last echo error but when I add the <code>http</code> in front of that URL it works find. I am checking the <code>$url</code> with  <code>PHP_URL_HOST</code> . </p>

<p>Why is it not accepting URLs of the allowed domain without the <code>http</code>? </p>

<p><strong>PHP</strong></p>

<pre><code>if ($_POST) {
    $url = $_POST['name'];

    if (!empty($url['name'])) {
        $allowed_domains = array(
            'www.youtube.com',
            'gdata.youtube.com',
            'youtu.be',
            'youtube.com',
            'm.youtube.com'
        );

        if (in_array(parse_url($url, PHP_URL_HOST), $allowed_domains)) {

            $formatted_url = getYoutubeVideoID($url);
            $parsed_url = parse_url($formatted_url);
            parse_str($parsed_url['query'], $parsed_query_string);
            $videoID = $parsed_query_string['v'];

            $headers = get_headers('http://gdata.youtube.com/feeds/api/videos/' . $videoID);

            if ($videoID != null) {

                if (strpos($headers[0], '200')) {
                    echo('&lt;div id="special"&gt;&lt;span id="resultval"&gt;That is a valid youtube video&lt;/span&gt;&lt;/div&gt;');

                }
                else {

                    echo('&lt;div id="special"&gt;&lt;span id="resultval"&gt;The YouTube video does not exist.&lt;/span&gt;&lt;/div&gt;');
                    return false;
                }

            }
            {

                echo('&lt;div id="special"&gt;&lt;span id="resultval"&gt;The YouTube video does not exist.&lt;/span&gt;&lt;/div&gt;');
                return false;
            }
        }
        else {

            echo ('&lt;div id="special"&gt;&lt;span id="resultval"&gt;Please include a video URL from Youtube.&lt;/span&gt;&lt;/div&gt;');

        }
        ?&gt;
</code></pre>
