フォントを選択するために、選択ボックスで Google Web フォントのリストを取得したいと考えています。次の関数を試していますが、エラーが発生します。
コード:
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;
}
エラー:
Warning: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP.
https を http に変更すると、次のエラーが発生します。
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
これは、変更できないサーバーの PHP 設定が原因だと思います。では、Google からフォント リストを取得する別の方法はありますか? ありがとう。