Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 0 => string '"Datasheets","Image","Digi-Key Part Number","Manufacturer Part Number","Manufacturer","Description","Quantity Available","Factory Stock","Unit Price (USD)","@ qty","Minimum Quantity","Series","Accessory Type","Material","Color","For Use With/Related Products"' (length=262)
- 1 => string '"http://www.knowles.com/eng/content/download/3165/37817/version/2/file/bf-1861-000.pdf","http://media.digikey.com/Photos/Knowles%20Acoustics%20Photos/BF-1861-000.jpg","423-1158-ND","BF-1861-000","Knowles","ACOUSTIC DAMPER 1500 OHMS",1067,0,"1.67000",0,1,"BF","Damper","Metal Ferrule Housing","Green","Hearing Aids"' (length=314)
- array (size=16)
- 0 => string '"Datasheets"' (length=15)
- 1 => string '"Image"' (length=7)
- 2 => string '"Digi-Key Part Number"' (length=22)
- 3 => string '"Manufacturer Part Number"' (length=26)
- 4 => string '"Manufacturer"' (length=14)
- 5 => string '"Description"' (length=13)
- 6 => string '"Quantity Available"' (length=20)
- 7 => string '"Factory Stock"' (length=15)
- 8 => string '"Unit Price (USD)"' (length=18)
- 9 => string '"@ qty"' (length=7)
- 10 => string '"Minimum Quantity"' (length=18)
- 11 => string '"Series"' (length=8)
- 12 => string '"Accessory Type"' (length=16)
- 13 => string '"Material"' (length=10)
- 14 => string '"Color"' (length=7)
- 15 => string '"For Use With/Related Products"' (length=31)
- $aKeys = json_decode( '[' . $strings[0] . ']');
- $aVals = json_decode( '[' . $strings[1] . ']');
- if( is_null( $aKeys) || is_null( $aVals) || ( count( $aKeys) != count( $aVals))) { // что могло пойти не так?!
- return;
- }
- return array_combine( $aKeys, $aVals);
- function filt( $s) {
- return filter_var(
- $s,
- FILTER_SANITIZE_STRING,
- FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_NO_ENCODE_QUOTES
- );
- }
- $url = "http://www.digikey.com/product-search/download.csv?FV=fff4000b%2Cfff80054&mnonly=0&newproducts=0&ColumnSort=0&page=1&stock=0&pbfree=0&rohs=0&quantity=0&ptm=0&fid=0&pageSize=500";
- $curl = curl_init();
- curl_setopt_array(
- $curl,
- array(
- CURLOPT_URL => $url
- , CURLOPT_HEADER => 0
- , CURLOPT_RETURNTRANSFER => 1
- )
- );
- $out = curl_exec($curl);
- // очистить лишние символы
- $item_dan = array_map( "filt", explode("n", $out));
- // из каждой строки сделать массив по запятой снаружи кавычек
- $items = array_map( "str_getcsv", $item_dan);
- print_r( $items);
- $keys_string = 'Тут строка с индексом [0] из исходного массива';
- $values_string = 'Тут строка с индексом [1] из исходного массива';
- $keys = explode(',', $keys_string); // Это массив, который вы хотели получить
- $values = explode(',', $values_string);
- $data = array_combine($keys, $values);
- print_r($data);
- Array
- (
- ["Datasheets"] => "http://www.knowles.com/eng/content/download/3165/37817/version/2/file/bf-1861-000.pdf"
- ["Image"] => "http://media.digikey.com/Photos/Knowles%20Acoustics%20Photos/BF-1861-000.jpg"
- ["Digi-Key Part Number"] => "423-1158-ND"
- ["Manufacturer Part Number"] => "BF-1861-000"
- ["Manufacturer"] => "Knowles"
- ["Description"] => "ACOUSTIC DAMPER 1500 OHMS"
- ["Quantity Available"] => 1067
- ["Factory Stock"] => 0
- ["Unit Price (USD)"] => "1.67000"
- ["@ qty"] => 0
- ["Minimum Quantity"] => 1
- ["Series"] => "BF"
- ["Accessory Type"] => "Damper"
- ["Material"] => "Metal Ferrule Housing"
- ["Color"] => "Green"
- ["For Use With/Related Products"] => "Hearing Aids"
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement