I am using php.
I have these lines of text in textbox:
Technology, Sciene
Domains
www.abc.de
http://cdf.com
something.co.uk
Health, Wellness
Domains
wellness.com
wellbeing.de
feelgood.ca
feelawesome.de.vu
My php script is getting each line into an array which I loop through later. What I want: delete every line that is not a domain or link.`
Note: My domains do not necessarily come with a http
or www.
What code I came up with so far:
preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url);
I would add an "http://"
if there is non already and then run the code above...
But it doesn't work.
The Line "Domain"
still gets recognized as a valid domain.
Any Idea?
Off the top of my head:
foreach($arrayItem as $item){
$validUrls[] = filter_var($item, FILTER_VALIDATE_URL);
}
But you could make this suit your purposes perhaps a bit better by looking into filter_var and it's array-friendly counter-part -- as well as some of the alternative filters that aren't picky about http:// or www.
if(preg_match('/^(https?:\/\/)?([\w-~]{2,}\.){1,3}(com|uk|de|ca|vu)(\/.*)?$/i',$host[$i])){
...
}
or:
if(preg_match('/^(https?:\/\/)?([\w-~]{2,}\.){1,3}[a-z]{2-13}(\/.*)?$/i',$host[$i])){
...
}
\w stands for [a-zA-Z0-9_]
See on Wiki: top level domains what's possible.