Re: How can I load this XML file into an array? (and. . . how do I reference the values?)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



this works:
$xml_data = file('xml_edwr2.xml');
var_dump($xml_data);
 
I can get the var_dump to work for 1 sample, but I guess there are a many samples in one xml file which turns into something like this(so, there is no way for me to reference a "column"):
 
array(9780) { [0]=> string(19) " " [1]=> string(23) " " [2]=> string(35) " " [3]=> string(38) " " [4]=> string(89) " 10943 " [5]=> string(95) " STATE " [6]=> string(39) " " [7]=> string(36) " " [8]=> string(24) " " [9]=> string(42) " " [10]=> string(78) " CCHD " [11]=> string(82) " 01316-TC/ECZ " [12]=> string(67) " NY0930054 " [13]=> string(86) " DISTRIBUTION " [14]=> string(62) " TC " [15]=> string(82) " SP " [16]=> string(83) " FSD " [17]=> string(83) " N " [18]=> string(83) " N " [19]=> string(41) " " [20]=> string(84) " MATT DOYLE " [21]=> string(42) " " [22]=> string(88) " 2006-02-06 " [23]=> string(86) " 12:00:00 " [24]=> string(38) " " [25]=> string(71) " 100 " [26]=> string(91) " 3 " [27]=> string(39) " " [28]=> string(48) " " [29]=> string(71) " 0.2 " [30]=> string(91) " 1 " [31]=> string(116) " FreeChlorineResidual " [32]=> string(49) " " [33]=> string(48) " " [34]=> string(71) " 0.2 " [35]=> string(91) " 1 " [36]=> string(117) " TotalChlorineResidual " [37]=> string(49) " " [38]=> string(48) " " [39]=> string(70) " 72 " [40]=> string(67) " F " [41]=> string(91) " 2 " [42]=> string(112) " WaterTemperature " [43]=> string(49) " " [44]=> string(48) " " [45]=> string(69) " 2 " [46]=> string(91) " 1 " [47]=> string(105) " Turbidity " [48]=> string(49) " " [49]=> string(48) " " [50]=> string(69) " 4 " [51]=> string(91) " 1 " [52]=> string(98) " PH " [53]=> string(49) " " [54]=> string(48) " " [55]=> string(71) " 200 " [56]=> string(91) " 3 " [57]=> string(104) " FlowRate " [58]=> string(49) " " [59]=> string(40) " " [60]=> string(60) " 2/9/2006 " [61]=> string(41) " " [62]=> string(80) " TC " [63]=> string(43) " " [64]=> string(50) " " [65]=> string(87) " RR SINK " [66]=> string(70) " DS " [67]=> string(51) " " [68]=> string(25) " " [69]=> string(24) " " [70]=> string(42) " " [71]=> string(78) " CCHD " [72]=> string(82) " 01370-TC/ECZ " [73]=> string(67) " NY0930094 " [74]=> string(86) " DISTRIBUTION " [75]=> string(62) " TC " [76]=> string(82) " SP " [77]=> string(83) " N " [78]=> string(83) " N " [79]=> string(41) " " [80]=> string(85) " LIZ TEDFORD " [81]=> string(42) " " [82]=> string(88) " 2006-02-07 " [83]=> string(84) " BP " [84]=> string(38) " " [85]=> string(71) " 100 " [86]=> string(91) " 3 " [87]=> string(39) " " [88]=> string(40) " " [89]=> string(60) " 2/9/2006 " [90]=> string(41) " " [91]=> string(80) " TC " [92]=> string(43) " " [93]=> string(50) " " [94]=> string(90) " COFFEE BAR " [95]=> string(70) " DS " [96]=> string(51) " " [97]=> string(25) " " [98]=> string(24) " " [99]=> string(42) " " [100]=> string(82) " 01596-TC/ECZ " [101]=> string(67) " NY0922914 " [102]=> string(77) " 137 " [103]=> string(62) " TC " [104]=> string(82) " RT " [105]=> string(83) " Y " [106]=> string(83) " N " [107]=> string(41) " " [108]=> string(76) " SB " [109]=> string(42) " " [110]=> string(88) " 2006-02-13 " [111]=> string(38) " " [112]=> string(71) " 100 " [113]=> string(91) " 3 " [114]=> string(39) " " [115]=> string(40) " " [116]=> string(61) " 2/21/2006 " [117]=> string(41) " " [118]=> string(80) " TC " [119]=> string(43) " " [120]=> string(50) " " [121]=> string(89) " LOT 1 CWT " [122]=> string(70) " DS " [123]=> string(51) " " [124]=> string(25) " " [125]=> string(24) " " [126]=> string(42) " " [127]=> string(78) " CCHD " [128]=> string(82) " 01604-TC/ECZ " [129]=> string(67) " NY0900220 " [130]=> string(77) " 140 " [131]=> string(62) " TC " [132]=> string(82) " SP " [133]=> string(83) " N " [134]=> string(83) " N " [135]=> string(41) " " [136]=> string(87) " TIM SIMONETTE " [137]=> string(42) " " [138]=> string(88) " 2006-02-13 " [139]=> string(38) " " [140]=> string(71) " 100 " [141]=> string(91) " 3 " [142]=> string(39) " " [143]=> string(48) " " [144]=> string(71) " 0.4 " [145]=> string(91) " 1 " [146]=> string(116) " FreeChlorineResidual " [147]=> string(49) " " [148]=> string(40) " " [149]=> string(61) " 2/15/2006 " [150]=> string(41) " " [151]=> string(80) " TC " [152]=> string(43) " " [153]=> string(50) " " [154]=> string(90) " 24 RAND HL " [155]=> string(70) " DS " [156]=> string(51) " " [157]=> string(25) " " [158]=> string(24) " " [159]=> string(42) " " [160]=> string(78) " CCHD " [161]=> string(82) " 01664-TC/ECZ " [162]=> string(67) " NY0922471 " [163]=> string(79) " 52848 " [164]=> string(62) " TC " [165]=> string(82) " SP " [166]=> string(83) " N " [167]=> string(83) " N " [168]=> string(41) " " [169]=> string(84) " MATT DOYLE " [170]=> string(42) " " [171]=> string(88) " 2006-02-14 " [172]=> string(38) " " [173]=> string(71) " 100 " [174]=> string(91) " 3 " [175]=> string(39) " " [176]=> string(48) " " [177]=> string(71) " 0.4 " [178]=> string(91) " 1 " [179]=> string(116) " FreeChlorineResidual " [180]=> string(49) " " [181]=> string(40) " " [182]=> string(61) " 2/16/2006 " [183]=> string(41) " " [184]=> string(80) " TC " [185]=> string(43) " " [186]=> string(50) " " [187]=> string(85) " LOT 9 " [188]=> string(70) " DS " [189]=> string(51) " " [190]=> string(25) " " [191]=> string(24) " " [192]=> string(42) " " [193]=> string(78) " CCHD " [194]=> string(82) " 01772-TC/ECZ " [195]=> string(67) " NY0904192 " [196]=> string(79) " 52708 " [197]=> string(62) " TC " [198]=> string(82) " SP " [199]=> string(83) " N " [200]=> string(83) " N " [201]=> string(41) " " [202]=> string(85) " LIZ TEDFORD " [203]=> string(42) " " [204]=> string(88) " 2006-02-15 " [205]=> string(38) " " [206]=> string(71) " 100 " [207]=> string(91) " 3 " [208]=> string(39) " " [209]=> string(48) " " [210]=> string(71) " 0.2 " [211]=> string(91) " 1 " [212]=> string(116) " FreeChlorineResidual " [213]=> string(49) " " [214]=> string(40) " " [215]=> string(61) " 2/17/2006 " [216]=> string(41) " " [217]=> string(80) " TC " [218]=> string(43) " " [219]=> string(50) " " [220]=> string(88) " MOP ROOM " [221]=> string(78) " POWERHOUSE " [222]=> string(51) " " [223]=> string(25) " " [224]=> string(24) " " [225]=> string(42) " " [226]=> string(78) " CCHD " [227]=> string(82) " 01773-TC/ECZ " [228]=> string(67) " NY0920796 " [229]=> string(86) " DISTRIBUTION " [230]=> string(62) " TC " [231]=> string(82) " SP " [232]=> string(83) " N " [233]=> string(83) " N " [234]=> string(41) " " [235]=> string(87) " TIM SIMONETTE " [236]=> string(42) " " [237]=> string(88) " 2006-02-15 " [238]=> string(38) " " [239]=> string(71) " 100 " [240]=> string(91) " 3 " [241]=> string(39) " " [242]=> string(40) " " [243]=> string(61) " 2/21/2006 " [244]=> string(41) " " [245]=> string(80) " TC " [246]=> string(43) " " [247]=> string(50) " " [248]=> string(91) " UTILITY CWT " [249]=>

>>> "mike" <mike503@xxxxxxxxx> 10/26/2007 2:58:52 PM >>>
On 10/26/07, John A DAVIS <John.A.Davis@xxxxxxxxxxx> wrote:
>
>
> I've found simple examples on the web that work a simple XML file (song,
> title, etc) but I need one that will parse an XML file into elements of an
> array. And then, I need to reference these elements to validate against a
> database. The data has to do with drinking water lab samples:

use simplexml (php.net/simplexml)

you may need to do string replacement though, replacing "EN:" with
"EN_" or something; having ":" has proven to be complex for me in the
past.

$xml = file_get_contents('file.xml');
$xml = str_replace('EN:', 'EN_', $xml);
$sxml = simplexml_load_string($xml);
var_dump($sxml);

that should be enough to get you started... enjoy!

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux