2016-07-21 12 views
0

私は1つのサイトからのデータをクロールしていると私は、次の文字列を取得:どのようにPHPでデータのjavascriptを処理するには?

var image_data11723 = [ { "type_code": "", "image_data": [ "graphics\/00000001\/COA389-l\u005F3\u005F350x280.jpg", "graphics\/00000001\/COA389-l\u005F3\u005F65x52.jpg", "graphics\/00000001\/COA389-l\u005F3.jpg" ] } ,{ "type_code": "", "image_data": [ "graphics\/00000001\/COA389-Dinette 1\u005F350x280.jpg", "graphics\/00000001\/COA389-Dinette 1\u005F65x52.jpg", "graphics\/00000001\/COA389-Dinette 1.jpg" ] } ,{ "type_code": "", "image_data": [ "graphics\/00000001\/COA389-Poker Table 1\u005F350x280.jpg", "graphics\/00000001\/COA389-Poker Table 1\u005F65x52.jpg", "graphics\/00000001\/COA389-Poker Table 1.jpg" ] } ,{ "type_code": "", "image_data": [ "graphics\/00000001\/COA389-Pool Table 1\u005F350x280.jpg", "graphics\/00000001\/COA389-Pool Table 1\u005F65x52.jpg", "graphics\/00000001\/COA389-Pool Table 1.jpg" ] } ,{ "type_code": "", "image_data": [ "graphics\/00000001\/COA389-Table CLoseup\u005F350x280.jpg", "graphics\/00000001\/COA389-Table CLoseup\u005F65x52.jpg", "graphics\/00000001\/COA389-Table CLoseup.jpg" ] } ,{ "type_code": "", "image_data": [ "graphics\/00000001\/COA389-Chair 1\u005F350x280.jpg", "graphics\/00000001\/COA389-Chair 1\u005F65x52.jpg", "graphics\/00000001\/COA389-Chair 1.jpg" ] } ] var im11723 = new ImageMachine('COA389', 0, 'main\u005Fimage', 'thumbnails', 'closeup\u005Fdiv', 'closeup\u005Fimage', 'closeup\u005Fclose', '', 'B', 350, 360, 1, 'N', 900, 675, 1, 65, 65, 1, 'graphics\/00000001\/COA389.1-i.jpg'); im11723.oninitialize(image_data11723); 

私はimage_data変数から配列を取得したいが、私はこれを実現する方法がわかりません。

+0

応答はあなたがしたい配列を、取得するためにjson_decodeを使用することができますJSON形式であるとか、あなたが見ることができます。 – Dharmendra

+0

クローラからJsでデータを取得しましたか? –

+0

ようこそスタックオーバーフロー!スタックオーバーフローは、無料のコード作成サービスではありません、あなたのコード/努力と実際の問題が何であるかを示してください。 – FrankerZ

答えて

0

まず、あなたがFirefoxの上Firebugアドオンでこれを取得しますあなたのVAR

<?php 
ini_set("allow_url_fopen", true); 

$jsonStr = file_get_contents("php://input"); //read the HTTP body. 
$json = json_decode($jsonStr, true); 
$result_array = array(); 
foreach ($json as $key => $value) { 
    foreach ($value['image_data'] as $key_2 => $value_2) { 
     $result_array[0][] = $value_2; 
    } 
} 
print_r($result_array); 
?> 

listener = jsOnChange.phpでjavascript

このような
data = JSON.stringify(image_data11723); 
$.ajax({ 
    type: "POST", 
    url: "jsOnChange.php", 
    // The key needs to match your method's input parameter (case-sensitive). 
    data: data, 
    contentType: "application/json; charset=utf-8", 
    dataType: "json", 
    async: false, 
    error: function(e) 
    {  
     alert(JSON.stringify(e, null, 4));       
    }, 
    success: function(strDrivers){ 
     alert(JSON.stringify(strDrivers, null, 4)); 
    } 
}); 

を構築するには。 Chrome

enter image description here

+0

Quynh Nguyenに感謝、私はpreg_match_allを試してみました。 :D私は非常にデータを持っています。私はそれを使用するので。 http://prntscr.com/bvm9im –

+0

@AlexMatoああ、そうですか? preg_match_allにはjavascriptの値を使用できます....? –

+1

はい preg_match_all( '/ "graphics((!!(\。jpg)))。* \。jpg" /'、$ str、$ matchs); $ dataImage = json_decode( '['。implode( "、"、$ matchs [0])。 ']'); –

関連する問題