Skip to content

Instantly share code, notes, and snippets.

@kasparsd
Created August 6, 2015 13:34
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 kasparsd/b97de7dfd9836421495b to your computer and use it in GitHub Desktop.
Save kasparsd/b97de7dfd9836421495b to your computer and use it in GitHub Desktop.
Extract Twitter username from links to Twitter profiles
<?php
$html = file_get_contents( 'http://example.com' );
preg_match_all( '/https?:\/\/(?:www.)?twitter.com\/#?([a-zA-Z0-9_]+)\/?(?![\/a-z]+)/i', $html, $maybe_twitters );
if ( ! empty( $maybe_twitters[1] ) ) {
printf( 'Found %s', $maybe_twitters[1][0] );
} else {
print( 'Nothing found!' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment