Skip to content

Instantly share code, notes, and snippets.

@eusonlito
Last active August 29, 2015 13:57
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 eusonlito/9429432 to your computer and use it in GitHub Desktop.
Save eusonlito/9429432 to your computer and use it in GitHub Desktop.
<?php
$urls = array(
'http://google.com/',
'https://google.com/',
'https://google.com?q=Google',
'https://google.com/search?q=Google',
'https://google.com/search/?q=Google&limit=10',
'https://google.com/search/?q=Google#results',
);
echo '<pre>';
foreach ($urls as $url) {
preg_match('#^([^:]+)://([^/\?]+)*[^/\?]?(/[^\?]*)*(\?[^\#]*)*#', $url, $match);
echo '<h1>'.$url.'</h1>';
var_dump($match);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment