php - Get font name from Google Fonts URL with regular expression -
please tell me how preg_match
font names google fonts url.
for example, want extract font name from:
http://fonts.googleapis.com/css?family=oswald:400,300 http://fonts.googleapis.com/css?family=roboto+slab
in order font names oswald
, roboto slab
.
here's example of might preg_replace(), careful data mining google.
<?php $urls = array("http://fonts.googleapis.com/css?family=oswald:400,300", "http://fonts.googleapis.com/css?family=roboto+slab"); $patterns = array( //replace path root '!^http://fonts.googleapis.com/css\?!', //capture family , avoid , following attributes in uri. '!(family=[^&:]+).*$!', //delete variable name '!family=!', //replace plus sign '!\+!'); $replacements = array( "", '$1', '', ' '); foreach($urls $url){ $font = preg_replace($patterns,$replacements,$url); echo $font; } ?>
Comments
Post a Comment