gpt4 book ai didi

php - 生成 XML

转载 作者:行者123 更新时间:2023-12-04 19:32:10 26 4
gpt4 key购买 nike

我制作了一个脚本,它可以根据 Mysql 数据库中的一些表生成 XML。
该脚本在 PHP 中运行。

public function getRawMaterials($apiKey, $format = 'json') {
if($this::checkApiKey($apiKey)) {
if(!Cache::has($apiKey . '_rawMaterialData')) {
$companyID = DB::table('apiKeys')
->select('companyID')
->where('apiKey', $apiKey)
->pluck('companyID');

$rawMaterials = DB::table('rawMaterials')
->join('companySupplier', 'companySupplier.supplier', '=', 'rawMaterials.supplierID')
->where('companySupplier.company', $companyID)
->take(3)
->get();

$nutritions = DB::table('nevoExpl')->select('nutrientcode', 'nederlandse_nutrientnaam', 'meeteenheid_nutrient')->get();
$allergens = DB::table('allergens')->get();
$dangers = DB::table('dangers')->get();

$data = (array)$rawMaterials;

for($i = 0; $i < sizeof($data); $i++) {

$data[$i] = (array)$data[$i];

// Initialize these variables
$data[$i]['ingredients'] = array();
$data[$i]['nutritions'] = array();
$data[$i]['allergens'] = array();
//$data[$i]['dangers'] = array();

$ingredients = DB::table('ingredients')
->select('ingredients.*', 'rawMaterialIngredients.weight')
->join('rawMaterialIngredients', 'rawMaterialIngredients.ingredientID', '=', 'ingredients.ingredientID')
->where('rawMaterialIngredients.rawMaterialID', $data[$i]['rawMaterialID'])
->get();

$data[$i]['ingredients'] = (array)$ingredients;

for($j = 0; $j < sizeof($data[$i]['ingredients']); $j++) {

$data[$i]['ingredients'][$j] = (array)$ingredients[$j];

// Check what allergens are in the products
foreach($allergens as $allergen) {
if(array_key_exists($allergen->allergen, $data[$i])) {
if(!array_key_exists($allergen->allergen, $data[$i]['allergens']) && $data[$i][$allergen->allergen] == "M") {
$data[$i]['allergens'][$allergen->id] = array(
'allergenID' => $allergen->id,
'allergenName' => $allergen->allergen,
'allergenValue' => 'M'
);
}

unset($data[$i][$allergen->allergen]);
}

if(array_key_exists($allergen->allergen, $data[$i]['ingredients'][$j])) {
if(!array_key_exists($allergen->allergen, $data[$i]['allergens']) && $data[$i]['ingredients'][$j][$allergen->allergen] == "M") {
$data[$i]['allergens'][$allergen->id] = array(
'allergenID' => $allergen->id,
'allergenName' => $allergen->allergen,
'allergenValue' => 'M'
);
}

unset($data[$i]['ingredients'][$j][$allergen->allergen]);
}
}

// foreach($dangers as $danger) {
// if(array_key_exists($danger->danger, $data[$i]['ingredients'][$j])) {
// if(array_key_exists($danger->danger, $data[$i]['dangers'])) {
// $data[$i]['dangers'][$danger->danger] = "M";
// }

// unset($data[$i]['ingredients'][$j][$danger->danger]);
// }
// }
}

foreach($nutritions as $nutrition) {
if(!array_key_exists($nutrition->nutrientcode, $data[$i]['nutritions'])) {
$data[$i]['nutritions'][] = array(
'nutritionCode' => $nutrition->nutrientcode,
'nutritionName' => $nutrition->nederlandse_nutrientnaam,
'nutritionMeasure' => $nutrition->meeteenheid_nutrient,
'nutritionValue' => $data[$i][$nutrition->nutrientcode]
);
}

// Don't need this anymore, so let's get rid of it!
unset($data[$i][$nutrition->nutrientcode]);
}
}

$data['Generated_on'] = date('d-m-Y G:i:s', time());

Cache::put($apiKey . '_rawMaterialData', $data, 720);

}
else {
$data = Cache::get($apiKey . '_rawMaterialData');
}
}
else {
$data['error'] = 'Dit is geen geldige API code.';
}

return $this::format($data, $format);
}

使用这个脚本的问题是它在处理大量数据时内存不足。
然而,我们需要处理这么多数据,因为我们想要制作一个可供客户使用的 xml。

目前我们将此脚本作为 API 运行,但我们愿意接受其他建议(甚至是与 PHP 无关的建议)
我们只是想要一种将我们的产品(到 API、FTP 或其他)导出到 XML(和 JSON)文件的方法,以便我们的客户可以使用它。我们也希望它是轻量级的。我们还希望它具有以下级别:
<xml>
<item>
<rawMaterialID>567</rawMaterialID>
<rawMaterialName>Gehakt 60 40 HOH</rawMaterialName>
<rawMaterialSpecDate>2014-10-19 16:17:14</rawMaterialSpecDate>
<rawMaterialSpecSource>koetsier vleeswaren bv</rawMaterialSpecSource>
<supplierID>28</supplierID>
<supplierDescription>gehakt hoh</supplierDescription>
<articleNumber>60250</articleNumber>
<supplierArticleNumber>2002733</supplierArticleNumber>
<barCode>0</barCode>
<originCountry>1</originCountry>
<productionCountry>1</productionCountry>
<id>1</id>
<company>15</company>
<supplier>28</supplier>
<ingredients>
<ingredient>
<ingredientID>226</ingredientID>
<ingredientName>varkensvlees</ingredientName>
<ingredientNameIMIS>varkensvlees</ingredientNameIMIS>
<enumber/>
<enumberAddition/>
<general_comments/>
<further_info/>
<albaList>Varkensvlees</albaList>
<adi/>
<aeromonas>Z</aeromonas>
<baccereus>Z</baccereus>
<campylobact>Z</campylobact>
<clostbot>Z</clostbot>
<clost_Perf>Z</clost_Perf>
<e_coli>Z</e_coli>
<e_coli_O157H7>Z</e_coli_O157H7>
<listeria>Z</listeria>
<salmonella>Z</salmonella>
<shigella>Z</shigella>
<staph_Aur>Z</staph_Aur>
<staph_coag>Z</staph_coag>
<yersinia>Z</yersinia>
<vibrio_col>Z</vibrio_col>
<vibrio_para>Z</vibrio_para>
<vibrio_vuln>Z</vibrio_vuln>
<mycobacteria>Z</mycobacteria>
<brucella>Z</brucella>
<aflatoxin>Z</aflatoxin>
<patuline>Z</patuline>
<echratoxin>Z</echratoxin>
<fusarium>Z</fusarium>
<ergot>Z</ergot>
<fumonisin>Z</fumonisin>
<rubratoxin>Z</rubratoxin>
<zearalenone>Z</zearalenone>
<hepatitis>Z</hepatitis>
<viral_gastroenteritis>Z</viral_gastroenteritis>
<polio>Z</polio>
<rickets>Z</rickets>
<prions>Z</prions>
<moulds_yeast>Z</moulds_yeast>
<anisakis_marina>Z</anisakis_marina>
<cryptosporidium_parvum>Z</cryptosporidium_parvum>
<echinococcus_granulosis>Z</echinococcus_granulosis>
<entamoeba_histolytica>Z</entamoeba_histolytica>
<giardia_lamblia>Z</giardia_lamblia>
<fasciola_hepatica>Z</fasciola_hepatica>
<clonorchis_sinensis>Z</clonorchis_sinensis>
<taenia_saginata>Z</taenia_saginata>
<taenia_solium>Z</taenia_solium>
<toxoplasma_gondii>Z</toxoplasma_gondii>
<trichinella_spiralis>Z</trichinella_spiralis>
<meelmijt_Tyroglyphus_farinae_L>Z</meelmijt_Tyroglyphus_farinae_L>
<flies>Z</flies>
<ants>Z</ants>
<mites>Z</mites>
<beetles>Z</beetles>
<cockroaches>Z</cockroaches>
<moths>Z</moths>
<rodents>Z</rodents>
<weevils>Z</weevils>
<bone_fragments>Z</bone_fragments>
<stones>Z</stones>
<insect_fragments>Z</insect_fragments>
<choke>Z</choke>
<metal_fragments>Z</metal_fragments>
<glass>Z</glass>
<createdBy/>
<dateCreated>2014-07-02 14:38:22</dateCreated>
<changedBy/>
<dateChanged/>
<weight>600</weight>
</ingredient>
<ingredient>
<ingredientID>200</ingredientID>
<ingredientName>rundvlees</ingredientName>
<ingredientNameIMIS>rundvlees</ingredientNameIMIS>
<enumber/>
<enumberAddition/>
<general_comments/>
<further_info/>
<albaList>Rundvlees</albaList>
<adi/>
<aeromonas>Z</aeromonas>
<baccereus>Z</baccereus>
<campylobact>Z</campylobact>
<clostbot>Z</clostbot>
<clost_Perf>Z</clost_Perf>
<e_coli>Z</e_coli>
<e_coli_O157H7>Z</e_coli_O157H7>
<listeria>Z</listeria>
<salmonella>Z</salmonella>
<shigella>Z</shigella>
<staph_Aur>Z</staph_Aur>
<staph_coag>Z</staph_coag>
<yersinia>Z</yersinia>
<vibrio_col>Z</vibrio_col>
<vibrio_para>Z</vibrio_para>
<vibrio_vuln>Z</vibrio_vuln>
<mycobacteria>Z</mycobacteria>
<brucella>Z</brucella>
<aflatoxin>Z</aflatoxin>
<patuline>Z</patuline>
<echratoxin>Z</echratoxin>
<fusarium>Z</fusarium>
<ergot>Z</ergot>
<fumonisin>Z</fumonisin>
<rubratoxin>Z</rubratoxin>
<zearalenone>Z</zearalenone>
<hepatitis>Z</hepatitis>
<viral_gastroenteritis>Z</viral_gastroenteritis>
<polio>Z</polio>
<rickets>Z</rickets>
<prions>Z</prions>
<moulds_yeast>Z</moulds_yeast>
<anisakis_marina>Z</anisakis_marina>
<cryptosporidium_parvum>Z</cryptosporidium_parvum>
<echinococcus_granulosis>Z</echinococcus_granulosis>
<entamoeba_histolytica>Z</entamoeba_histolytica>
<giardia_lamblia>Z</giardia_lamblia>
<fasciola_hepatica>Z</fasciola_hepatica>
<clonorchis_sinensis>Z</clonorchis_sinensis>
<taenia_saginata>Z</taenia_saginata>
<taenia_solium>Z</taenia_solium>
<toxoplasma_gondii>Z</toxoplasma_gondii>
<trichinella_spiralis>Z</trichinella_spiralis>
<meelmijt_Tyroglyphus_farinae_L>Z</meelmijt_Tyroglyphus_farinae_L>
<flies>Z</flies>
<ants>Z</ants>
<mites>Z</mites>
<beetles>Z</beetles>
<cockroaches>Z</cockroaches>
<moths>Z</moths>
<rodents>Z</rodents>
<weevils>Z</weevils>
<bone_fragments>Z</bone_fragments>
<stones>Z</stones>
<insect_fragments>Z</insect_fragments>
<choke>Z</choke>
<metal_fragments>Z</metal_fragments>
<glass>Z</glass>
<createdBy/>
<dateCreated>2014-07-02 14:38:22</dateCreated>
<changedBy/>
<dateChanged/>
<weight>400</weight>
</ingredient>
</ingredients>
<nutritions>
<nutrition>
<nutritionCode>n_01001</nutritionCode>
<nutritionName>Energie</nutritionName>
<nutritionMeasure>kcal</nutritionMeasure>
<nutritionValue>233</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_01002</nutritionCode>
<nutritionName>Energie</nutritionName>
<nutritionMeasure>kJ</nutritionMeasure>
<nutritionValue>969</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_02001</nutritionCode>
<nutritionName>Stikstof totaal</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>3.1</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_02002</nutritionCode>
<nutritionName>Eiwit totaal</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>19.2</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_02003</nutritionCode>
<nutritionName>Eiwit plantaardig</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_02004</nutritionCode>
<nutritionName>Eiwit dierlijk</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>19.2</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_03001</nutritionCode>
<nutritionName>Vet totaal</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>17.2</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_03002</nutritionCode>
<nutritionName>Som van de vetzuren</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>16.2</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_03004</nutritionCode>
<nutritionName>Vetzuren totaal verzadigd</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>6.9</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_03006</nutritionCode>
<nutritionName>Vetzuren enkelv onverz cis</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>7.5</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_03008</nutritionCode>
<nutritionName>Vetzuren meerv onverz</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>1.3</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_03009</nutritionCode>
<nutritionName>Linolzuur (C18:2(n-6)cis)</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>1.1</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_03136</nutritionCode>
<nutritionName>Vetzuren totaal trans</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_04001</nutritionCode>
<nutritionName>Cholesterol</nutritionName>
<nutritionMeasure>mg</nutritionMeasure>
<nutritionValue>28.8</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_05001</nutritionCode>
<nutritionName>Koolhydraten totaal</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>0.3</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_05002</nutritionCode>
<nutritionName>Suiker Totaal</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>0.3</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_05003</nutritionCode>
<nutritionName>Glucose</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_05005</nutritionCode>
<nutritionName>Fructose</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_05006</nutritionCode>
<nutritionName>Lactose</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_05008</nutritionCode>
<nutritionName>Maltose</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_05009</nutritionCode>
<nutritionName>Saccharose</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_05010</nutritionCode>
<nutritionName>Polysacchariden totaal</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_05011</nutritionCode>
<nutritionName>Polyolen totaal</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_05012</nutritionCode>
<nutritionName>Lactitol</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_05013</nutritionCode>
<nutritionName>Xylitol</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_05014</nutritionCode>
<nutritionName>Sorbitol</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_05015</nutritionCode>
<nutritionName>Isomalt</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_06001</nutritionCode>
<nutritionName>Voedingsvezel totaal</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>0.3</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_07001</nutritionCode>
<nutritionName>Water</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>63.7</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_08001</nutritionCode>
<nutritionName>Alcohol totaal</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_09001</nutritionCode>
<nutritionName>Calcium</nutritionName>
<nutritionMeasure>mg</nutritionMeasure>
<nutritionValue>9</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_09002</nutritionCode>
<nutritionName>Fosfor</nutritionName>
<nutritionMeasure>mg</nutritionMeasure>
<nutritionValue>169</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_09003</nutritionCode>
<nutritionName>IJzer totaal</nutritionName>
<nutritionMeasure>mg</nutritionMeasure>
<nutritionValue>1.3</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_09006</nutritionCode>
<nutritionName>Natrium</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>0.177</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_09007</nutritionCode>
<nutritionName>Kalium</nutritionName>
<nutritionMeasure>mg</nutritionMeasure>
<nutritionValue>303</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_09008</nutritionCode>
<nutritionName>Magnesium</nutritionName>
<nutritionMeasure>mg</nutritionMeasure>
<nutritionValue>19</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_09009</nutritionCode>
<nutritionName>Zink</nutritionName>
<nutritionMeasure>mg</nutritionMeasure>
<nutritionValue>3.22</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_10001</nutritionCode>
<nutritionName>Selenium</nutritionName>
<nutritionMeasure>ug</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_10002</nutritionCode>
<nutritionName>Koper</nutritionName>
<nutritionMeasure>mg</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_10003</nutritionCode>
<nutritionName>Jodium</nutritionName>
<nutritionMeasure>ug</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_11001</nutritionCode>
<nutritionName>Retinol</nutritionName>
<nutritionMeasure>ug</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_11002</nutritionCode>
<nutritionName>Retinol equivalenten</nutritionName>
<nutritionMeasure>ug</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_11003</nutritionCode>
<nutritionName>Beta-caroteen</nutritionName>
<nutritionMeasure>ug</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_11005</nutritionCode>
<nutritionName>Vitamine B1</nutritionName>
<nutritionMeasure>mg</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_11006</nutritionCode>
<nutritionName>Vitamine B2</nutritionName>
<nutritionMeasure>mg</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_11007</nutritionCode>
<nutritionName>Vitamine B6 totaal</nutritionName>
<nutritionMeasure>mg</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_11008</nutritionCode>
<nutritionName>Vitamine B12</nutritionName>
<nutritionMeasure>ug</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_11009</nutritionCode>
<nutritionName>Vitamine D totaal</nutritionName>
<nutritionMeasure>ug</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_11010</nutritionCode>
<nutritionName>Vitamine E totaal</nutritionName>
<nutritionMeasure>mg</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_11011</nutritionCode>
<nutritionName>Vitamine C</nutritionName>
<nutritionMeasure>mg</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_11013</nutritionCode>
<nutritionName>Foliumzuur</nutritionName>
<nutritionMeasure>ug</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_11014</nutritionCode>
<nutritionName>Nicotinezuur</nutritionName>
<nutritionMeasure>mg</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_11020</nutritionCode>
<nutritionName>Alfa-caroteen</nutritionName>
<nutritionMeasure>ug</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_11022</nutritionCode>
<nutritionName>Zeaxanthine</nutritionName>
<nutritionMeasure>ug</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_11024</nutritionCode>
<nutritionName>Lycopeen</nutritionName>
<nutritionMeasure>ug</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_11035</nutritionCode>
<nutritionName>Vitamine K totaal</nutritionName>
<nutritionMeasure>ug</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_11036</nutritionCode>
<nutritionName>Vitamine K1</nutritionName>
<nutritionMeasure>ug</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_11038</nutritionCode>
<nutritionName>Vitamine K2</nutritionName>
<nutritionMeasure>ug</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_11039</nutritionCode>
<nutritionName>Zout</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_11040</nutritionCode>
<nutritionName>Omega 3 vetzuren N-3</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
<nutrition>
<nutritionCode>n_11041</nutritionCode>
<nutritionName>Omega 6 vetzuren N-6</nutritionName>
<nutritionMeasure>g</nutritionMeasure>
<nutritionValue>0</nutritionValue>
</nutrition>
</nutritions>
<allergens>
<allergen>
<allergenID>14</allergenID>
<allergenName>rundvlees</allergenName>
<allergenValue>M</allergenValue>
</allergen>
<allergen>
<allergenID>15</allergenID>
<allergenName>varkensvlees</allergenName>
<allergenValue>M</allergenValue>
</allergen>
</allergens>
</item>
</xml>

我希望有人可以帮助我们。

最佳答案

什么时候抛出错误?数据量是多少?

如果在格式化操作期间发生内存不足错误,也许您可​​以将您的大 json 或 xml 拆分为多个文件,然后将它们连接起来。

但是在任何情况下你应该做的真正的事情是如果你的数据库包含 100 万条记录,那么你的输出页面最多可以输出 n 个实体,这并不奇怪你的 php 提示内存......

如果你不这样做,你的客户会遇到同样的问题,当他们试图解析你的数据时内存不足......

关于php - 生成 XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27254833/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com