ortolojf
WRInaute accro
Bonjour
Je me bat avec le code PHP ci-dessous, qui marche sans erreur isolé ( premier log ci-dessous ) , mais à l'intérieur du script tmp_geny_res.php , la variable de boucle $j s'incrémente théoriquement ( sinon la boucle serait infinie ), mais apparemment elle semble rester à 0. ( deuxième log ci-dessous ).
J' ai cherché toutes les variables globales de nom $j : Il n'y en pas.
Où est l'erreur ?
Dans tmp_geny_res.php ( mode séquentiel, pas objet ), le code php ci-dessous est bien délimité, et les arrays sont correctement alimentées.
L'erreur est dans la boucle interne ( $j ).
Je suis sous Linux Fedora 33 64 bits x86_64, sous PHP 7.4.15.
Merci beaucoup de votre aide.
Amicalement.
PHP ci-dessus sans autre code.
Je me bat avec le code PHP ci-dessous, qui marche sans erreur isolé ( premier log ci-dessous ) , mais à l'intérieur du script tmp_geny_res.php , la variable de boucle $j s'incrémente théoriquement ( sinon la boucle serait infinie ), mais apparemment elle semble rester à 0. ( deuxième log ci-dessous ).
J' ai cherché toutes les variables globales de nom $j : Il n'y en pas.
Où est l'erreur ?
Dans tmp_geny_res.php ( mode séquentiel, pas objet ), le code php ci-dessous est bien délimité, et les arrays sont correctement alimentées.
L'erreur est dans la boucle interne ( $j ).
Je suis sous Linux Fedora 33 64 bits x86_64, sous PHP 7.4.15.
Merci beaucoup de votre aide.
Amicalement.
PHP:
<?php
function to_vide($str)
{
$str = preg_replace("{^[ \t]+}", "", $str);
$str = preg_replace("{[ \t]+$}", "", $str);
return($str);
}
function compare($nom_1, $nom_2)
{
//
// Il faut éliminer
// ce qui suit un caractère
// [ ou ] inclus
// dans les deux paramètres.
//
// En effet, ce qui suit
// contient souvent
// des données
// peu interprétables
// et gênantes.
//
$pos = strpos($nom_1, "[");
if($pos !== false)
$nom_1 = substr($nom_1, 0, $pos);
unset($pos);
$pos = strpos($nom_1, "]");
if($pos !== false)
$nom_1 = substr($nom_1, 0, $pos);
unset($pos);
$pos = strpos($nom_2, "[");
if($pos !== false)
$nom_2 = substr($nom_2, 0, $pos);
unset($pos);
$pos = strpos($nom_2, "]");
if($pos !== false)
$nom_2 = substr($nom_2, 0, $pos);
$nom_1 = to_vide($nom_1);
$nom_2 = to_vide($nom_2);
$nom_1 = str_replace("-", ":", $nom_1);
$nom_2 = str_replace("-", ":", $nom_2);
$nom_1 = str_replace("Â", "A", $nom_1);
$nom_2 = str_replace("Â", "A", $nom_2);
$nom_1 = str_replace("Ê", "E", $nom_1);
$nom_2 = str_replace("Ê", "E", $nom_2);
$nom_1 = str_replace("Î", "I", $nom_1);
$nom_2 = str_replace("Î", "I", $nom_2);
$nom_1 = str_replace("Ô", "O", $nom_1);
$nom_2 = str_replace("Ô", "O", $nom_2);
$nom_1 = str_replace("Û", "U", $nom_1);
$nom_2 = str_replace("Û", "U", $nom_2);
$nom_1 = preg_replace("{[ \t]+}", ":", $nom_1);
$nom_2 = preg_replace("{[ \t]+}", ":", $nom_2);
$nom_1 = preg_replace("{[:]+}", ":", $nom_1);
$nom_2 = preg_replace("{[:]+}", ":", $nom_2);
$nom_1 = preg_replace("{^[:]+}", "", $nom_1);
$nom_1 = preg_replace("{[:]+$}", "", $nom_1);
$nom_2 = preg_replace("{^[:]+}", "", $nom_2);
$nom_2 = preg_replace("{[:]+$}", "", $nom_2);
$nom_1 = str_replace(":", " ", $nom_1);
$nom_2 = str_replace(":", " ", $nom_2);
// On vérifie d'abord
// si les paramètres
// ne contiennent pas
// les mêmes mots
// dans le désordre
// ou dans l'ordre.
//
echo "\t\t" . '$nom_1 = ' . $nom_1 . "\n\n";
echo "\t\t" . '$nom_2 = ' . $nom_2 . "\n\n";
if($nom_1 == $nom_2)
{
return(true);
}
$array_nom1 = array();
$array_nom2 = array();
$array_nom1 = preg_split("{[ ]+}", $nom_1);
$array_nom2 = preg_split("{[ ]+}", $nom_2);
$k = 0;
$tmp = "";
// On prend le mot le plus long
// identique dans les deux
// arrays.
//
// Il faut éliminer
// les adverbes courts.
//
for($i = 0; $i < count($array_nom1); $i++)
{
for($j = 0; $j < count($array_nom2); $j++)
{
if(($array_nom1[$i] == $array_nom2[$j])&&($array_nom1[$i] != "DES")&&($array_nom1[$i] != "SUR")&&($array_nom1[$i] != "AUX")&&($array_nom1[$i] != "LES")&&($array_nom1[$i] != "SUD")&&($k < strlen($array_nom1[$i])))
{
$k = strlen($array_nom1[$i]);
$tmp = $array_nom1[$i];
}
}
}
// Il peut n'y avoir
// que le mot : "PAU"
// qui fait trois
// caractères.
//
if(($k > 0)&&(strlen($tmp) > 2))
{
return(true);
}
else
{
return(false);
}
}
$array_nom_reunion = array();
$courses_nom_reunion = array();
$array_nom_reunion[ 0 ] = 'PARIS:VINCENNES';
$array_nom_reunion[ 1 ] = 'TURFFONTEIN';
$array_nom_reunion[ 2 ] = 'MONT:DE:MARSAN';
$array_nom_reunion[ 3 ] = 'PORNICHET';
$array_nom_reunion[ 4 ] = 'U.A.E:MEYDAN';
$array_nom_reunion[ 5 ] = 'NEWCASTLE';
$k_max = 5;
$courses_nom_reunion[ 0] = 'VINCENNES';
$courses_nom_reunion[ 1] = 'TURFFONTEIN';
$courses_nom_reunion[ 2] = 'MONT:DE:MARSAN';
$courses_nom_reunion[ 3] = 'PORNICHET:LA:BAULE';
$courses_nom_reunion[ 4] = 'MEYDAN';
$courses_nom_reunion[ 5] = 'NEWCASTLE';
$courses_nom_reunion[ 6] = 'GULFSTREAM:PARK';
$courses_nom_reunion[ 7] = 'CONCEPCION';
$o_max = 7;
unset($array_indice);
$array_indice = array();
for($i = 0; $i <= 100; $i++)
$array_indice[$i] = -1;
//
// Tous les indices trouvés
// sont corrects, il suffit
// ensuite de parcourir
// cet indice,
// de sélectionner les indices différents
// de - 1 ( indices trouvés ),
// puis d'utiliser la valeur de l'indice
// pour accéder à la Réunion correcte.
//
unset($trouve_reunion);
$trouve_reunion = array();
$r = 0;
echo "\t\t" . '$o_max = ' . $o_max . "\n";
for($i = 0; $i <= $k_max; $i++)
{
unset($nom_reunion_1);
// Nom Réunion Partants
// de la base de données.
$nom_reunion_1 = $array_nom_reunion[$i];
for($j = 0; $j <= $o_max; $j++)
{
unset($nom_reunion_2);
// Nom Réunion Résultats
// de Geny.com
$nom_reunion_2 = $courses_nom_reunion[$j];
echo "\t\t" . '$array_nom_reunion[ ' . $i . ' ] = ' . $nom_reunion_1 . "\n";
echo "\t\t" . '$courses_nom_reunion[ ' . $j . ' ] = ' . $nom_reunion_2 . "\n\n";
// Si la comparaison rend true,
// les deux noms de Réunions
// sont considérés identiques,
// et l'appariement se fait.
//
if((compare($nom_reunion_1, $nom_reunion_2) === true)&&(in_array($j, $trouve_reunion, true) === false))
{
$trouve_reunion[$r] = $j;
$r++;
// Deux noms de Réunions
// identiques ont été trouvés.
$array_indice[$i] = $j;
print_r($trouve_reunion);
echo "\n\n";
break;
}
}
}
print_r($trouve_reunion);
echo "\n\n";
exit;
?>
PHP ci-dessus sans autre code.
Code:
$o_max = 7
$array_nom_reunion[ 0 ] = PARIS:VINCENNES
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = PARIS VINCENNES
$nom_2 = VINCENNES
Array
(
[0] => 0
)
$array_nom_reunion[ 1 ] = TURFFONTEIN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = TURFFONTEIN
$nom_2 = VINCENNES
$array_nom_reunion[ 1 ] = TURFFONTEIN
$courses_nom_reunion[ 1 ] = TURFFONTEIN
$nom_1 = TURFFONTEIN
$nom_2 = TURFFONTEIN
Array
(
[0] => 0
[1] => 1
)
$array_nom_reunion[ 2 ] = MONT:DE:MARSAN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = MONT DE MARSAN
$nom_2 = VINCENNES
$array_nom_reunion[ 2 ] = MONT:DE:MARSAN
$courses_nom_reunion[ 1 ] = TURFFONTEIN
$nom_1 = MONT DE MARSAN
$nom_2 = TURFFONTEIN
$array_nom_reunion[ 2 ] = MONT:DE:MARSAN
$courses_nom_reunion[ 2 ] = MONT:DE:MARSAN
$nom_1 = MONT DE MARSAN
$nom_2 = MONT DE MARSAN
Array
(
[0] => 0
[1] => 1
[2] => 2
)
$array_nom_reunion[ 3 ] = PORNICHET
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = PORNICHET
$nom_2 = VINCENNES
$array_nom_reunion[ 3 ] = PORNICHET
$courses_nom_reunion[ 1 ] = TURFFONTEIN
$nom_1 = PORNICHET
$nom_2 = TURFFONTEIN
$array_nom_reunion[ 3 ] = PORNICHET
$courses_nom_reunion[ 2 ] = MONT:DE:MARSAN
$nom_1 = PORNICHET
$nom_2 = MONT DE MARSAN
$array_nom_reunion[ 3 ] = PORNICHET
$courses_nom_reunion[ 3 ] = PORNICHET:LA:BAULE
$nom_1 = PORNICHET
$nom_2 = PORNICHET LA BAULE
Array
(
[0] => 0
[1] => 1
[2] => 2
[3] => 3
)
$array_nom_reunion[ 4 ] = U.A.E:MEYDAN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = U.A.E MEYDAN
$nom_2 = VINCENNES
$array_nom_reunion[ 4 ] = U.A.E:MEYDAN
$courses_nom_reunion[ 1 ] = TURFFONTEIN
$nom_1 = U.A.E MEYDAN
$nom_2 = TURFFONTEIN
$array_nom_reunion[ 4 ] = U.A.E:MEYDAN
$courses_nom_reunion[ 2 ] = MONT:DE:MARSAN
$nom_1 = U.A.E MEYDAN
$nom_2 = MONT DE MARSAN
$array_nom_reunion[ 4 ] = U.A.E:MEYDAN
$courses_nom_reunion[ 3 ] = PORNICHET:LA:BAULE
$nom_1 = U.A.E MEYDAN
$nom_2 = PORNICHET LA BAULE
$array_nom_reunion[ 4 ] = U.A.E:MEYDAN
$courses_nom_reunion[ 4 ] = MEYDAN
$nom_1 = U.A.E MEYDAN
$nom_2 = MEYDAN
Array
(
[0] => 0
[1] => 1
[2] => 2
[3] => 3
[4] => 4
)
$array_nom_reunion[ 5 ] = NEWCASTLE
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = NEWCASTLE
$nom_2 = VINCENNES
$array_nom_reunion[ 5 ] = NEWCASTLE
$courses_nom_reunion[ 1 ] = TURFFONTEIN
$nom_1 = NEWCASTLE
$nom_2 = TURFFONTEIN
$array_nom_reunion[ 5 ] = NEWCASTLE
$courses_nom_reunion[ 2 ] = MONT:DE:MARSAN
$nom_1 = NEWCASTLE
$nom_2 = MONT DE MARSAN
$array_nom_reunion[ 5 ] = NEWCASTLE
$courses_nom_reunion[ 3 ] = PORNICHET:LA:BAULE
$nom_1 = NEWCASTLE
$nom_2 = PORNICHET LA BAULE
$array_nom_reunion[ 5 ] = NEWCASTLE
$courses_nom_reunion[ 4 ] = MEYDAN
$nom_1 = NEWCASTLE
$nom_2 = MEYDAN
$array_nom_reunion[ 5 ] = NEWCASTLE
$courses_nom_reunion[ 5 ] = NEWCASTLE
$nom_1 = NEWCASTLE
$nom_2 = NEWCASTLE
Array
(
[0] => 0
[1] => 1
[2] => 2
[3] => 3
[4] => 4
[5] => 5
)
Array
(
[0] => 0
[1] => 1
[2] => 2
[3] => 3
[4] => 4
[5] => 5
)
Code:
PHP ci-dessus, à 'intérieur du script tmp_geny_res.php
<html>
<head>
<meta http-equiv="Pragma" content="no-cache">
<title>Arrivées Résultats</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
$courses_nom_reunion[ 0] = VINCENNES
$courses_num_reunion[ 0] = 1
$courses_nom_reunion[ 1] = TURFFONTEIN
$courses_num_reunion[ 1] = 2
$courses_nom_reunion[ 2] = MONT:DE:MARSAN
$courses_num_reunion[ 2] = 3
$courses_nom_reunion[ 3] = PORNICHET:LA:BAULE
$courses_num_reunion[ 3] = 4
$courses_nom_reunion[ 4] = MEYDAN
$courses_num_reunion[ 4] = 5
$courses_nom_reunion[ 5] = NEWCASTLE
$courses_num_reunion[ 5] = 6
$courses_nom_reunion[ 6] = GULFSTREAM:PARK
$courses_num_reunion[ 6] = 7
$courses_nom_reunion[ 7] = CONCEPCION
$courses_num_reunion[ 7] = 8
$o_max = 7
$o_max = 7
$array_nom_reunion[ 0 ] = PARIS:VINCENNES
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = PARIS VINCENNES
$nom_2 = VINCENNES
Array
(
[0] => 0
)
$array_nom_reunion[ 1 ] = TURFFONTEIN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = TURFFONTEIN
$nom_2 = VINCENNES
$array_nom_reunion[ 1 ] = TURFFONTEIN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = TURFFONTEIN
$nom_2 = VINCENNES
$array_nom_reunion[ 1 ] = TURFFONTEIN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = TURFFONTEIN
$nom_2 = VINCENNES
$array_nom_reunion[ 1 ] = TURFFONTEIN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = TURFFONTEIN
$nom_2 = VINCENNES
$array_nom_reunion[ 1 ] = TURFFONTEIN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = TURFFONTEIN
$nom_2 = VINCENNES
$array_nom_reunion[ 1 ] = TURFFONTEIN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = TURFFONTEIN
$nom_2 = VINCENNES
$array_nom_reunion[ 1 ] = TURFFONTEIN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = TURFFONTEIN
$nom_2 = VINCENNES
$array_nom_reunion[ 1 ] = TURFFONTEIN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = TURFFONTEIN
$nom_2 = VINCENNES
$array_nom_reunion[ 2 ] = MONT:DE:MARSAN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = MONT DE MARSAN
$nom_2 = VINCENNES
$array_nom_reunion[ 2 ] = MONT:DE:MARSAN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = MONT DE MARSAN
$nom_2 = VINCENNES
$array_nom_reunion[ 2 ] = MONT:DE:MARSAN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = MONT DE MARSAN
$nom_2 = VINCENNES
$array_nom_reunion[ 2 ] = MONT:DE:MARSAN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = MONT DE MARSAN
$nom_2 = VINCENNES
$array_nom_reunion[ 2 ] = MONT:DE:MARSAN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = MONT DE MARSAN
$nom_2 = VINCENNES
$array_nom_reunion[ 2 ] = MONT:DE:MARSAN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = MONT DE MARSAN
$nom_2 = VINCENNES
$array_nom_reunion[ 2 ] = MONT:DE:MARSAN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = MONT DE MARSAN
$nom_2 = VINCENNES
$array_nom_reunion[ 2 ] = MONT:DE:MARSAN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = MONT DE MARSAN
$nom_2 = VINCENNES
$array_nom_reunion[ 3 ] = PORNICHET
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = PORNICHET
$nom_2 = VINCENNES
$array_nom_reunion[ 3 ] = PORNICHET
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = PORNICHET
$nom_2 = VINCENNES
$array_nom_reunion[ 3 ] = PORNICHET
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = PORNICHET
$nom_2 = VINCENNES
$array_nom_reunion[ 3 ] = PORNICHET
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = PORNICHET
$nom_2 = VINCENNES
$array_nom_reunion[ 3 ] = PORNICHET
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = PORNICHET
$nom_2 = VINCENNES
$array_nom_reunion[ 3 ] = PORNICHET
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = PORNICHET
$nom_2 = VINCENNES
$array_nom_reunion[ 3 ] = PORNICHET
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = PORNICHET
$nom_2 = VINCENNES
$array_nom_reunion[ 3 ] = PORNICHET
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = PORNICHET
$nom_2 = VINCENNES
$array_nom_reunion[ 4 ] = U.A.E:MEYDAN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = U.A.E MEYDAN
$nom_2 = VINCENNES
$array_nom_reunion[ 4 ] = U.A.E:MEYDAN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = U.A.E MEYDAN
$nom_2 = VINCENNES
$array_nom_reunion[ 4 ] = U.A.E:MEYDAN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = U.A.E MEYDAN
$nom_2 = VINCENNES
$array_nom_reunion[ 4 ] = U.A.E:MEYDAN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = U.A.E MEYDAN
$nom_2 = VINCENNES
$array_nom_reunion[ 4 ] = U.A.E:MEYDAN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = U.A.E MEYDAN
$nom_2 = VINCENNES
$array_nom_reunion[ 4 ] = U.A.E:MEYDAN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = U.A.E MEYDAN
$nom_2 = VINCENNES
$array_nom_reunion[ 4 ] = U.A.E:MEYDAN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = U.A.E MEYDAN
$nom_2 = VINCENNES
$array_nom_reunion[ 4 ] = U.A.E:MEYDAN
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = U.A.E MEYDAN
$nom_2 = VINCENNES
$array_nom_reunion[ 5 ] = NEWCASTLE
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = NEWCASTLE
$nom_2 = VINCENNES
$array_nom_reunion[ 5 ] = NEWCASTLE
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = NEWCASTLE
$nom_2 = VINCENNES
$array_nom_reunion[ 5 ] = NEWCASTLE
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = NEWCASTLE
$nom_2 = VINCENNES
$array_nom_reunion[ 5 ] = NEWCASTLE
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = NEWCASTLE
$nom_2 = VINCENNES
$array_nom_reunion[ 5 ] = NEWCASTLE
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = NEWCASTLE
$nom_2 = VINCENNES
$array_nom_reunion[ 5 ] = NEWCASTLE
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = NEWCASTLE
$nom_2 = VINCENNES
$array_nom_reunion[ 5 ] = NEWCASTLE
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = NEWCASTLE
$nom_2 = VINCENNES
$array_nom_reunion[ 5 ] = NEWCASTLE
$courses_nom_reunion[ 0 ] = VINCENNES
$nom_1 = NEWCASTLE
$nom_2 = VINCENNES
Array
(
[0] => 0
)