par
wisefun77 » 29 avr. 2022, 10:36
Bonjour,
Désolé de revenir si tard, mais dur dur la première semaine.
Voici ce que j'ai fait.
Code : Tout sélectionner
<?php
$string = "[ADC_START][SDP][GUICHET][DEM][USER_CMDB_DIF_NON][DEM_PDT_PCF < ASSET_XXX> < TPX_1>][DEM_PDT_PCF < ASSET_XXX> < TPX_1>][DEM_PDT_PCF < ASSET_XXX> < TPX_1>][DEM_PDT_PCF < ASSET_XXX> < TPX_1>][DEM_PDT_PCF < ASSET_XXX> < TPX_1>][DEM_PDT_PCF < ASSET_XXX> < TPX_1>][DEM_PDT_PCF < ASSET_XXX> < TPX_1>][DEM_PDT_PCF < ASSET_XXX> < TPX_1>][PRT_PRP < ASSET_ XXX < TPX_1>]7 [SFW_TLD < TPX_1 > ][RDV_NON][RDV_BAL][RSDP_NON][NO COMMENT][19f16457][22/04/22-17:12][Version_2.02][ADC_END] ";
// Définition du tableau final
$clean_array = [];
// On split la chaine selon les crochets ouvrants
$string_to_array = preg_split('#\[#i', $string);
foreach ($string_to_array AS $v) {
// On nettoie le string pour retirer le crochet fermant
$str = trim(str_replace(']', '', $v));
// Si la chaine n'est pas vide, on l'ajoute à notre tableau final
if (!empty($str)) {
$clean_array[] = $str;
}
}
//echo PHP_EOL . '<pre>$clean_array: ' . print_r($clean_array, true) . '</pre>' . PHP_EOL;
?>
<br/><br/>
------------------------ Recherche des donnees.
<br/><br/>
<?php
$tab = $clean_array;
if(in_array('RDV_NON',$tab)){
//------------------------ array_slice
$input =$tab;
// retourne chaine complète sans le numéro de la dernière balise.
$output = array_slice($input, 0);
// notez les clés d'index différentes
echo 'trouvé ARRAY ==> ';
print_r(array_slice($input,0));
// print_r(array_slice($input, 2, -1, true));
}
else{
echo 'pas trouvé';
}
?>
Cela affiche:
[15] => RDV_NON [16] => RDV_BAL [17] => RSDP_NON
Code : Tout sélectionner
trouvé ARRAY ==> Array ( [0] => ADC_START [1] => SDP [2] => GUICHET [3] => DEM [4] => USER_CMDB_DIF_NON [5] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [6] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [7] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [8] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [9] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [10] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [11] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [12] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [13] => PRT_PRP < ASSET_ XXX < TPX_1>7 [14] => SFW_TLD < TPX_1 > [15] => RDV_NON [16] => RDV_BAL [17] => RSDP_NON[18] => NO COMMENT [19] => 19f16457 [20] => 22/04/22-17:12 [21] => Version_2.02 [22] => ADC_END )
Mais je ne sais récupérer la clé d'index de la balise recherchée, pour tout reclasser.
Car il faudrait que la chaine soit ainsi.
Code : Tout sélectionner
Array ( [0] => ADC_START [1] => SDP [2] => GUICHET [3] => DEM[4] => USER_CMDB_DIF_NON[15] => RDV_NON [16] => RDV_BAL [17] => RSDP_NON [5] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [6] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [7] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [8] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [9] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [10] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [11] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [12] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [13] => PRT_PRP < ASSET_ XXX < TPX_1>7 [14] => SFW_TLD < TPX_1 >[18] => NO COMMENT [19] => 19f16457 [20] => 22/04/22-17:12 [21] => Version_2.02 [22] => ADC_END )
Merci.
Bonjour,
Désolé de revenir si tard, mais dur dur la première semaine.
Voici ce que j'ai fait.
[code]
<?php
$string = "[ADC_START][SDP][GUICHET][DEM][USER_CMDB_DIF_NON][DEM_PDT_PCF < ASSET_XXX> < TPX_1>][DEM_PDT_PCF < ASSET_XXX> < TPX_1>][DEM_PDT_PCF < ASSET_XXX> < TPX_1>][DEM_PDT_PCF < ASSET_XXX> < TPX_1>][DEM_PDT_PCF < ASSET_XXX> < TPX_1>][DEM_PDT_PCF < ASSET_XXX> < TPX_1>][DEM_PDT_PCF < ASSET_XXX> < TPX_1>][DEM_PDT_PCF < ASSET_XXX> < TPX_1>][PRT_PRP < ASSET_ XXX < TPX_1>]7 [SFW_TLD < TPX_1 > ][RDV_NON][RDV_BAL][RSDP_NON][NO COMMENT][19f16457][22/04/22-17:12][Version_2.02][ADC_END] ";
// Définition du tableau final
$clean_array = [];
// On split la chaine selon les crochets ouvrants
$string_to_array = preg_split('#\[#i', $string);
foreach ($string_to_array AS $v) {
// On nettoie le string pour retirer le crochet fermant
$str = trim(str_replace(']', '', $v));
// Si la chaine n'est pas vide, on l'ajoute à notre tableau final
if (!empty($str)) {
$clean_array[] = $str;
}
}
//echo PHP_EOL . '<pre>$clean_array: ' . print_r($clean_array, true) . '</pre>' . PHP_EOL;
?>
<br/><br/>
------------------------ Recherche des donnees.
<br/><br/>
<?php
$tab = $clean_array;
if(in_array('RDV_NON',$tab)){
//------------------------ array_slice
$input =$tab;
// retourne chaine complète sans le numéro de la dernière balise.
$output = array_slice($input, 0);
// notez les clés d'index différentes
echo 'trouvé ARRAY ==> ';
print_r(array_slice($input,0));
// print_r(array_slice($input, 2, -1, true));
}
else{
echo 'pas trouvé';
}
?>
[/code]
Cela affiche:
[15] => RDV_NON [16] => RDV_BAL [17] => RSDP_NON
[CODE]
trouvé ARRAY ==> Array ( [0] => ADC_START [1] => SDP [2] => GUICHET [3] => DEM [4] => USER_CMDB_DIF_NON [5] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [6] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [7] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [8] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [9] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [10] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [11] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [12] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [13] => PRT_PRP < ASSET_ XXX < TPX_1>7 [14] => SFW_TLD < TPX_1 > [15] => RDV_NON [16] => RDV_BAL [17] => RSDP_NON[18] => NO COMMENT [19] => 19f16457 [20] => 22/04/22-17:12 [21] => Version_2.02 [22] => ADC_END )
[/CODE]
Mais je ne sais récupérer la clé d'index de la balise recherchée, pour tout reclasser.
Car il faudrait que la chaine soit ainsi.
[CODE]
Array ( [0] => ADC_START [1] => SDP [2] => GUICHET [3] => DEM[4] => USER_CMDB_DIF_NON[15] => RDV_NON [16] => RDV_BAL [17] => RSDP_NON [5] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [6] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [7] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [8] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [9] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [10] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [11] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [12] => DEM_PDT_PCF < ASSET_XXX> < TPX_1> [13] => PRT_PRP < ASSET_ XXX < TPX_1>7 [14] => SFW_TLD < TPX_1 >[18] => NO COMMENT [19] => 19f16457 [20] => 22/04/22-17:12 [21] => Version_2.02 [22] => ADC_END )
[/CODE]
Merci.