Created
August 6, 2015 13:34
-
-
Save kasparsd/b97de7dfd9836421495b to your computer and use it in GitHub Desktop.
Extract Twitter username from links to Twitter profiles
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 | |
$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