2012-03-27 3 views
-1

나는 Avactis라는 장바구니를 사용합니다. 내 프런트 엔드에서 사용할 작은 "정보 태그"를 나에게 돌려줍니다. 모양은 다음과 같습니다.JSON에서 PHP 함수 사용하기 데이터

<?php ProductSmImage();?> 
<?php ProductName();?> 

내 제품에 Agile Carousel 스크립트를 사용하려고합니다. 작은 이미지, 제품 이름, 제품 대체 텍스트 및 제품 링크를 사용하고 싶습니다.

JSON 데이터 파일은 다음과 같다 :

[{ 
"content": "<div class='slide_inner'><a class='photo_link' href='#'><img class='photo' src='images/banner_bike.jpg' alt='Bike'></a><a class='caption' href='#'>Sample Carousel Pic Goes Here And The Best Part is that...</a></div>", 
"content_button": "<div class='thumb'><img src='images/f2_thumb.jpg' alt='bike is nice'></div><p>Agile Carousel Place Holder</p>" 
}] 

그리고 프론트 엔드의 스크립트는 다음과 같습니다

<script> 

// Code used for "Flavor 2" example (above) 

$.getJSON("agile_carousel/agile_carousel_data.php", function(data) { 
    $(document).ready(function(){ 
     $("#flavor_2").agile_carousel({ 

      // required settings 

      carousel_data: data, 
      carousel_outer_height: 330, 
      carousel_height: 230, 
      slide_height: 230, 
      carousel_outer_width: 480, 
      slide_width: 480, 

      // end required settings 

      transition_type: "fade", 
      transition_time: 600, 
      timer: 3000, 
      continuous_scrolling: true, 
      control_set_1: "numbered_buttons,previous_button, 
      ... (continues on same line)... pause_button,next_button", 
      control_set_2: "content_buttons", 
      change_on_hover: "content_buttons" 
     }); 
    }); 
}); 
그래서

, 나는 첫 번째 HREF을 대체 할 with와 이미지의 src 등등.

이 코드는 JSON 인코딩과 관련이 있다고 생각하지만 프로그래머가 아닙니다 (분명히) 태그를 JSON 데이터로 변환하는 코드를 어디에 쓰는지 알고 싶습니다. 따라야 할 코드는 영원히 감사 할 것입니다.

감사합니다.

+0

JSON 파일의 "]"실제로 JSON 파일에 있다고 가정합니다. – Hubro

+0

이 JSON 문자열을 만드는 코드를 게시 할 수 있습니까? 너는 그게 수정되기를 바랍 니? 당신이하고 싶은 것을 이해하는 것은 쉽지 않습니다 ... 당신이하고 싶은 언어로 ... – ManseUK

+0

¿ 어떻게이 json을 얻습니까? ¿ PHP 또는 jquery를 통해? – Patroklo

답변

0

일부 빠른 방법은 PHP를 사용하여 어떻게 할 수 있는지 묻습니다.

<?php 

$json = "[{ 
\"content\": \"<div class='slide_inner'><a class='photo_link' href='#'><img class='photo' src='images/banner_bike.jpg' alt='Bike'></a><a class='caption' href='#'>Sample Carousel Pic Goes Here And The Best Part is that...</a></div>\", 
\"content_button\": \"<div class='thumb'><img src='images/f2_thumb.jpg' alt='bike is nice'></div><p>Agile Carousel Place Holder</p>\" 
}]"; 

$data = json_decode($json); 

$content = $data[0]->content; 

$src = substr($content, strpos($content, 'src=') + 5); 
$src = substr($src, 1, strpos($src, "'")-1); 

$content = str_replace("href='#'", "href='$src'", $content); 

echo $content;