オカズリンクのサムネイル取得にて、特定のJSONのデコード前に改行コードをエスケープするようにした

This commit is contained in:
shibafu 2018-04-11 01:17:52 +09:00
parent 46f049c2b8
commit 0f39b502e8
1 changed files with 2 additions and 1 deletions

View File

@ -71,7 +71,8 @@ Route::get('/checkin/card', function (Request $request) {
// ニジエ用の処理
$dataNode = $xpath->query('//script[substring(@type, string-length(@type) - 3, 4) = "json"]');
foreach ($dataNode as $node) {
$imageData = json_decode($node->nodeValue, true);
// 改行がそのまま入っていることがあるのでデコード前にエスケープが必要
$imageData = json_decode(preg_replace('/\r?\n/', '\n', $node->nodeValue), true);
if (isset($imageData['thumbnailUrl'])) {
$result['image'] = preg_replace('~nijie\\.info/.*/nijie_picture/~', 'nijie.info/nijie_picture/', $imageData['thumbnailUrl']);
break;