php - Correct regex to detect font family names from google font link src -
i've been trying array of fonts i'm enqeueing on wordpress theme. testing.
on input:
http://fonts.googleapis.com/css?family=arimo:400,700|quicksand:400,700|cantarell:400,700,400italic,700italic|muli:300,400,300italic,400italic|roboto+slab:400,700|share:400,700,400italic,700italic|inconsolata:400,700|karla:400,700,400italic,700italic|maven+pro:400,500,700,900|roboto+slab:400,700|open+sans:400italic,600italic,700italic,400,600,700
what need on output this:
array( [0] => 'arimo', [1] => 'quicksand', [2] => 'cantarell', ... on )
till now, have done 1 little problem.
my code:
$input = 'http://fonts.googleapis.com/css?family=arimo:400,700|quicksand:400,700|cantarell:400,700,400italic,700italic|muli:300,400,300italic,400italic|roboto+slab:400,700|share:400,700,400italic,700italic|inconsolata:400,700|karla:400,700,400italic,700italic|maven+pro:400,500,700,900|roboto+slab:400,700|open+sans:400italic,600italic,700italic,400,600,700'; $against = "/[a-z][a-z]+[\+][a-z][a-z]+|[a-z][a-z]+/"; $matches = array() preg_match_all( $against, $input, $matches ); print_r($matches);
from this, output this:
array( 0 => arimo 1 => quicksand 2 => cantarell 3 => muli 4 => roboto+slab 5 => share 6 => inconsolata 7 => karla 8 => maven+pro 9 => roboto+slab 10 => open+sans )
there's +
sign font name has spaces. want rid of that.
i'm not regex expert. so, couldn't manage that.
note: know str_replace()
don't want go through long process. want know if it's possible escape +
sign through , leave empty space there when collecting matched expressions.
spaces encoded plus (+) signs in url. should decode url.
$input = urldecode($input);
Comments
Post a Comment