validate a url and then split it into the url and the domain name

113 Views Asked by At

Let say I have got a url

http://ex.com/blah?balchs

What I wanna do is to validate if the url is valid. The url

ex.com and /blah?balchs

How can I do this?

Also if I wanna validate if the domain exists and is up and running how do I do that? Also if I wanna validate if the url exists and is up and running how do I do that?

1

There are 1 best solutions below

0
On BEST ANSWER

You can try using built-in php functions for the first part, namely parse-url.

For the latter, it kinda depends on what you mean by "exists" and "running". The simplest technique is to do a ping and check if that succeeded. But this can be faulty at times. If the target machine is certain to have a port opened you can try fsockopen.