Last active
October 25, 2019 08:43
-
-
Save amirkhiz/f906bd1bace6d96ab8b368f7acf13562 to your computer and use it in GitHub Desktop.
Get potential domain from array of strings
This file contains 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 | |
function getPotentialDomains( $lines ) { | |
$re = '~((https|http){1}://(www|ww2|web)?(\.)?(([a-z0-9\-])+\.)+([a-z]{2,}){1})~ui'; | |
$domains = []; | |
foreach ( $lines as $line ) { | |
preg_match_all( $re, $line, $matches, PREG_SET_ORDER, 0 ); | |
$domains = array_merge( $domains, $matches ); | |
} | |
return implode( ',', $domains ); | |
} | |
echo getPotentialDomains( [ | |
'https://example.domain/page?=78', | |
'http://example.domain/page?=78', | |
'["Train (noun)"](https://www.askoxford.com/concise_oed/train?view=uk).', | |
'["Train (noun)"](http://aefae.askoxford.com/concise_oed/train?view=uk).' | |
] ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment