Hi, If I have a list of domains being submitted to a php script in one big string, how can I make sure that they're all proper domains ( I'll define the acceptable extensions ), put them into different array slots, and also format them into 'name.extension'? Any help would be appreciated
Also for splitting them into an array you'll want to use explode() and then a foreach loop to loop through the list of values
or parse_url() then http://mattiasgeniar.be/2009/02/07/input-validation-using-filter_var-over-regular-expressions/
The problem with the filter_var is that it allows email addresses such as username@1 which isnt exactly the kind of email you want
What do you mean by proper domains? Do you also want to check if they are actually used? Or do you just want to make sure that it could be a Domain. So anything like "asdsdadadsqqqqqxcaa1293.com" would be acceptable?
I basically want something that can turn a list like : http://www.google.com google.com www.google.com into just google.com google.com google.com
Follow this example: <?php $domain = "http://google.com"; //check if domains valid if (!filter_var($domain, FILTER_VALIDATE_URL)){ echo "Invalid URL"; } else { //format domain to look like "domain.extension"; $domain = parse_url($domain); echo "Valid URL"; echo $domain['host']; } ?> PHP:
FILTER_VALIDATE_URL will validate the following... http://-/ http://1/ So it's not all that reliable either, plus you would want to validate it before using parse_url
In that case, here's a better method: <?php $domains = array("http://google.com", "http://www.google.com", "http://google.com", "chipdcnv.com"); foreach ($domains as $domain){ if(!getmxrr($domain, $MXHost)){ $host = parse_url($domain); echo $host['host']." <br>"; } } ?> PHP: