Skip to content

Instantly share code, notes, and snippets.

@miladoll
Created March 1, 2021 07:45
Show Gist options
  • Select an option

  • Save miladoll/3d0d7ae518a103cbd993108643de88e9 to your computer and use it in GitHub Desktop.

Select an option

Save miladoll/3d0d7ae518a103cbd993108643de88e9 to your computer and use it in GitHub Desktop.
https://github.com/scottmac/opengraph/blob/master/OpenGraph.php へのdirty patch。EUC-JP、ShiftJISのサイトへ対応
diff --git "a/vendor/opengraph/OpenGraph.php" "b/vendor/opengraph/OpenGraph.php"
index aa16e55..92ccdff 100644
--- "a/vendor/opengraph/OpenGraph.php"
+++ "b/vendor/opengraph/OpenGraph.php"
@@ -61,6 +61,20 @@ class OpenGraph implements Iterator
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
$response = curl_exec($curl);
+ $suspicious_charset = '';
+ preg_match(
+ '/<meta\s+.*?charset=(euc-jp|shift_jis).*?>/ism',
+ $response,
+ $matches
+ );
+ $suspicious_charset = $matches[1];
+ if ( preg_match( '/shift_jis/i', $suspicious_charset ) ) {
+ $suspicious_charset = 'sjis';
+ }
+ $suspicious_charset = mb_strtoupper( $suspicious_charset );
+ if ( strlen($suspicious_charset) > 0 ) {
+ $response = mb_convert_encoding( $response, 'utf-8', $suspicious_charset );
+ }
curl_close($curl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment