Hello everyone,

I'm trying to write a script which accepts URL by GET and then validates the URL before processing it.

for the sake of arguement lets say that the URL I'm expecting is in this format

http://mysite.com/myscript.php?url=http://blahblah.blahblah.bla/blahblah/blahblah/blahblah.bla http://subdomain.domain.tld/section/category/file.ext 

I need to validate the part which is a link to a XML; i.e, my URL might be like these

http://gradefive.belmontprimary.edu/grades/science/peter.xml https://gradesix.belmontprimary.edu/grades/maths/geometry/lisa.xml http://gradeeight.belmontprimary.edu/grades/maths/calculus/sandra.xml 

I don't know wether if the XML files would be on a secure server (https) or unsecure one (non-https) at the moment, and also I don't know what the contents of the files may be. All I know for sure is that these are the XML files which I need to use for my project.

so far, I have snooped around and found this code

    function isValidURL($link)
        $urlregex = '^(https?|s?ftp\:\/\/)|(mailto\:)';
        $urlregex .= "[a-z0-9+$_-]+(.[a-z0-9+$_-]+)+";
        $urlregex .= '(\?[a-z\+&\$_\.\-][a-z0-9\;\:@\/&%=\+\$_\.\-]*)?';

        if(preg_match('/'.$urlregex.'/i', $link))
            return true;
            return false;

        function getXMLData($url){
        if(!isValidURL($url))   {
            echo "Please enter valid URL including http://<br>";

                $savedXML = file_get_contents($url);
                echo "thanks";
                return $savedXML;
            }catch(Exception $e){

but this is not what I exactly need. can anyone please help me by solving this issue?

thanks in advance.

Edited by emclondon

5 Years
Discussion Span
Last Post by pritaeas

You can write an elaborate regex to test most cases. You could just try to open the file. If it fails... no xml, or invalid url.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.