Skip to content

Instantly share code, notes, and snippets.

@amirkhiz
Last active October 25, 2019 08:43
Show Gist options
  • Save amirkhiz/f906bd1bace6d96ab8b368f7acf13562 to your computer and use it in GitHub Desktop.
Save amirkhiz/f906bd1bace6d96ab8b368f7acf13562 to your computer and use it in GitHub Desktop.
Get potential domain from array of strings
<?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