Skip to content

Instantly share code, notes, and snippets.

@ZiTAL
Forked from anonymous/regex.php
Created October 26, 2017 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZiTAL/12314b932c814b0ceffeb14fb690aab0 to your computer and use it in GitHub Desktop.
Save ZiTAL/12314b932c814b0ceffeb14fb690aab0 to your computer and use it in GitHub Desktop.
regex: detect internal domains in urls
<?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