I want to get list of google web fonts in select box to select a font. I am trying following function, but it gives the error.
Code:
function get_google_fonts() {
$url = "https://www.googleapis.com/webfonts/v1/webfonts?sort=alpha";
$result = json_response( $url );
$font_list = array();
foreach ( $result->items as $font ) {
$font_list[] .= $font->family;
}
return $font_list;
}
function json_response( $url ) {
$raw = file_get_contents( $url, 0, null, null );
$decoded = json_decode( $raw );
return $decoded;
}
Error:
Warning: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP.
If I change the https to http, I get this error:
file_get_contents(http://www.googleapis.com/webfonts/v1/webfonts?sort=alpha): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in
I guess this is because of PHP settings on my server, which I am unable to change. So, is there any alternative way to get the font list from Google? Thanks.