PHP is all about validation. If you don't validate then somewhere along the line, your application will fail. Hopefully it won't fail too badly, but any sort of unexpected output or non-handled error that a user notices is a huge fail.
One of the key classes I use in various projects is this one. It validates a URL with PHP.
First, take a look at the class:
PHP Code:
<?php
class Validate_Url {
    private $url;
    /**
     * Initiate the class giving a url.
     *
     * @param string $url
     */
    public function __construct($url)
    {
        $this->url = $url;
    }
    /**
     * Validate the given URL from the __construct
     * @return boolean true for valid / false for invalid.
     */
    public function isValid()
    {
        $regex = '^(https?)\:\/\/([a-z0-9+!*(),;?&=$_.-]+(\:[a-z0-9+!*(),;?&=$_.-]+)?@)?[a-z0-9+$_-]+(\.[a-z0-9+$_-]+)*(:[0-9]{2,5})?(\/([a-z0-9+$_-]\.?)+)*\/?(\?[a-z+&$_.-][a-z0-9;:@/&%=+$_.-]*)?(#[a-z_.-][a-z0-9+$_.-]*)?$^';
        if (preg_match($regex, $this->url)) {
            return true;
        }
        return false;
    }
}
Here's how you can use it:
PHP Code:
<?php
$class = new Validate_Url("http://www.example.com/test.php");
if ($class->isValid()) {
    // URL is valid.
    echo "Valid URL.";
}
else {
    // URL is not valid.
    echo "URL is not valid.";
}
