Created
October 26, 2017 10:35
-
-
Save anonymous/34cfaea1cf71dcc5dc5224612b6d63ab to your computer and use it in GitHub Desktop.
regex: detect internal domains in urls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$allow = array | |
( | |
'*.eitb.*', | |
'tortolika' | |
); | |
$urls = array | |
( | |
'www.eitb.eus/asjdhjashdjahjkdhajkhdjk/', | |
'http://www.eitb.eus/asjdhjashdjahjkdhajkhdjk/', | |
'http://pre.eitb.eus/', | |
'http://tortolika/', | |
'tortolika/adasdasdass', | |
'http://www.google.es', | |
'www.google.es' | |
); | |
$z = array(); | |
foreach($urls as $url) | |
{ | |
foreach($allow as $a) | |
{ | |
$b = preg_replace("/\./", '\.', $a); | |
$b = preg_replace("/\*/", '[^\s]+', $a); | |
$b = "^(https?:\/\/|){$b}"; | |
if(preg_match("/$b/i", $url)) | |
$z[] = $url; | |
} | |
} | |
print_r($z); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
Array
(
[0] => www.eitb.eus/asjdhjashdjahjkdhajkhdjk/
[1] => http://www.eitb.eus/asjdhjashdjahjkdhajkhdjk/
[2] => http://pre.eitb.eus/
[3] => http://tortolika/
[4] => tortolika/adasdasdass
)