첨부소스의경우 파싱을위한 정규식은 어떠케...

첨부소스의경우 파싱을위한 정규식은 어떠케...

QA

첨부소스의경우 파싱을위한 정규식은 어떠케...

답변 2

본문

아래내용을 파싱을위한 정규식으로 가능할까요?

 

<script type="application/ld+json">[{"@context" : "http://schema.org","@type" : "LocalBusiness","name" : "속초관광호텔","image" : "http://cdn.jalan.jp/jalan/img/0/kuchikomi/1490/KXL/16221_0001490548_3.JPG","url" : "http://www.jalan.net/kankou/spt_guide000000184294/","aggregateRating" : {"@type" : "AggregateRating","ratingValue" : "4.4","ratingCount" : "772"}} 

이 질문에 댓글 쓰기 :

답변 2


<?php
$str = '<script type="application/ld+json">[{"@context" : "http://schema.org","@type" : "LocalBusiness","name" : "속초관광호텔","image" : "http://cdn.jalan.jp/jalan/img/0/kuchikomi/1490/KXL/16221_0001490548_3.JPG","url" : "http://www.jalan.net/kankou/spt_guide000000184294/","aggregateRating" : {"@type" : "AggregateRating","ratingValue" : "4.4","ratingCount" : "772"}}]</script>';
preg_match('/<script type="application\/ld\+json">(.+)<\/script>/', $str, $matches);
$parsed = json_decode($matches[1], true); 
var_dump($parsed);

 

이건  json 입니다. 

JSON.parse() 으로 가능합니다.

 

자세한 내용은

http://www.w3schools.com/js/js_json.asp

을 참고하시기 바랍니다. 

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 129,112
© SIRSOFT
현재 페이지 제일 처음으로