Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. 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)
  2. 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)
  3.  
  4. array (size=16)
  5. 0 => string '"Datasheets"' (length=15)
  6. 1 => string '"Image"' (length=7)
  7. 2 => string '"Digi-Key Part Number"' (length=22)
  8. 3 => string '"Manufacturer Part Number"' (length=26)
  9. 4 => string '"Manufacturer"' (length=14)
  10. 5 => string '"Description"' (length=13)
  11. 6 => string '"Quantity Available"' (length=20)
  12. 7 => string '"Factory Stock"' (length=15)
  13. 8 => string '"Unit Price (USD)"' (length=18)
  14. 9 => string '"@ qty"' (length=7)
  15. 10 => string '"Minimum Quantity"' (length=18)
  16. 11 => string '"Series"' (length=8)
  17. 12 => string '"Accessory Type"' (length=16)
  18. 13 => string '"Material"' (length=10)
  19. 14 => string '"Color"' (length=7)
  20. 15 => string '"For Use With/Related Products"' (length=31)
  21.  
  22. $aKeys = json_decode( '[' . $strings[0] . ']');
  23. $aVals = json_decode( '[' . $strings[1] . ']');
  24.  
  25. if( is_null( $aKeys) || is_null( $aVals) || ( count( $aKeys) != count( $aVals))) { // что могло пойти не так?!
  26. return;
  27. }
  28.  
  29. return array_combine( $aKeys, $aVals);
  30.  
  31. function filt( $s) {
  32. return filter_var(
  33. $s,
  34. FILTER_SANITIZE_STRING,
  35. FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_NO_ENCODE_QUOTES
  36. );
  37. }
  38.  
  39. $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";
  40.  
  41. $curl = curl_init();
  42. curl_setopt_array(
  43. $curl,
  44. array(
  45. CURLOPT_URL => $url
  46. , CURLOPT_HEADER => 0
  47. , CURLOPT_RETURNTRANSFER => 1
  48. )
  49. );
  50.  
  51. $out = curl_exec($curl);
  52.  
  53. // очистить лишние символы
  54. $item_dan = array_map( "filt", explode("n", $out));
  55.  
  56. // из каждой строки сделать массив по запятой снаружи кавычек
  57. $items = array_map( "str_getcsv", $item_dan);
  58.  
  59. print_r( $items);
  60.  
  61. $keys_string = 'Тут строка с индексом [0] из исходного массива';
  62. $values_string = 'Тут строка с индексом [1] из исходного массива';
  63.  
  64. $keys = explode(',', $keys_string); // Это массив, который вы хотели получить
  65. $values = explode(',', $values_string);
  66.  
  67. $data = array_combine($keys, $values);
  68. print_r($data);
  69.  
  70. Array
  71. (
  72. ["Datasheets"] => "http://www.knowles.com/eng/content/download/3165/37817/version/2/file/bf-1861-000.pdf"
  73. ["Image"] => "http://media.digikey.com/Photos/Knowles%20Acoustics%20Photos/BF-1861-000.jpg"
  74. ["Digi-Key Part Number"] => "423-1158-ND"
  75. ["Manufacturer Part Number"] => "BF-1861-000"
  76. ["Manufacturer"] => "Knowles"
  77. ["Description"] => "ACOUSTIC DAMPER 1500 OHMS"
  78. ["Quantity Available"] => 1067
  79. ["Factory Stock"] => 0
  80. ["Unit Price (USD)"] => "1.67000"
  81. ["@ qty"] => 0
  82. ["Minimum Quantity"] => 1
  83. ["Series"] => "BF"
  84. ["Accessory Type"] => "Damper"
  85. ["Material"] => "Metal Ferrule Housing"
  86. ["Color"] => "Green"
  87. ["For Use With/Related Products"] => "Hearing Aids"
  88. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement