par
blinz » 18 juil. 2015, 17:02
Salut à tous.
J'ai un ptit bout de code qui permet d'intégrer des données dans une base de donnée tout marche très bien en local mais pas en ligne ....
/****** FONCTIONS ******/
function suppr_accents($string) {
return str_replace( array('à','á','â','ã','ä', 'ç', 'è','é','ê','ë', 'ì','í','î','ï', 'ñ', 'ò','ó','ô','õ','ö', 'ù','ú','û','ü', 'ý','ÿ', 'À','Á','Â','Ã','Ä', 'Ç', 'È','É','Ê','Ë', 'Ì','Í','Î','Ï', 'Ñ', 'Ò','Ó','Ô','Õ','Ö', 'Ù','Ú','Û','Ü', 'Ý'), array('a','a','a','a','a', 'c', 'e','e','e','e', 'i','i','i','i', 'n', 'o','o','o','o','o', 'u','u','u','u', 'y','y', 'A','A','A','A','A', 'C', 'E','E','E','E', 'I','I','I','I', 'N', 'O','O','O','O','O', 'U','U','U','U', 'Y'), $string);
}
//set_time_limit(0);
// On défini les id à parcourir
$id = 98000 ;
while ($id < 98005) {
$adresse = "http://www.lesite_$id.php" ; // adresse de la page à exploiter
$page = @file_get_contents ($adresse); // récupérer le contenu de la page
echo 'id :' .$id;
// Titre
$titre = @eregi('<h1>(.*)</h1>',$page,$nom);
// explode sur le titre pour ne récupèrer que le type
$pieces = explode(" - ", $nom[1]);
echo "$pieces[1] <BR>" ;
$nom_evenement = addslashes($pieces[1]);
// Date
$date = @eregi('<tr style="font-weight: bold; background: #FFFFFF; font-size: 12px;">
<td style="color: #a2141e; width: 150px; padding-left: 5px;">Date : </td>
<td>(.*)</td>
</tr>
<tr style="font-weight: bold; background: #E8E8E8; font-size: 12px;">
<td style="color: #a2141e; width: 150px; padding-left: 5px;">Lieu : </td>',$page,$event);
// Traitement de la date ( conversion de type texte en format sql )
$texte_original="$event[1]";
$jourmois_fr = array('janvier', 'fevrier', 'mars', 'avril', 'mai', 'juin', 'juillet', 'aout', 'septembre', 'octobre', 'novembre', 'decembre', 'lundi ', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche');
$jourmois_en = array('january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday');
$timestamp=strtotime(str_replace($jourmois_fr, $jourmois_en, strtolower(suppr_accents($texte_original))));
$date_debut = date("Y-m-d", $timestamp);
echo $date_debut .'<br>';
// Ville
$ville = @eregi('<tr style="font-weight: bold; background: #E8E8E8; font-size: 12px;">
<td style="color: #a2141e; width: 150px; padding-left: 5px;">Lieu : </td>
<td>(.*)</td>
</tr>
<tr style="font-weight: bold; background: #FFFFFF; font-size: 12px;">
<td style="color: #a2141e; padding-left: 5px;">Précision lieu : </td>',$page,$lieu);
echo "$lieu[1] <BR>" ;
$nom_ville = addslashes($lieu[1]);
// on crée la requête SQL
$sql = "SELECT cp FROM `cp_autocomplete` WHERE `ville` LIKE '".addslashes($lieu[1])."' ORDER BY cp DESC LIMIT 0, 1 ";
// on envoie la requête
$req = mysql_query($sql);
// on fait une boucle qui va faire un tour pour chaque enregistrement
while($data = mysql_fetch_assoc($req))
{
// on affiche les informations de l'enregistrement en cours
echo $data['cp'] .'<br><br>' ;
// On attribut le département en fonction des 2 premiers chiffre du code postal
$departement = substr($data['cp'], 0, 2);
$codepostal = substr($data['cp'], 0, 5);
echo 'département' .$departement. '<br><br>';
}
// Téléphone
$phone = @eregi('<tr style="font-weight: bold; background: #E8E8E8; font-size: 12px;">
<td style="color: #a2141e; padding-left: 5px;">Contact téléphone : </td>
<td>(.*)</tr>
<tr style="font-weight: bold; background: #FFFFFF; font-size: 12px;">
<td style="color: #a2141e; padding-left: 5px;">Contact email : </td>',$page,$tel);
echo "$tel[1] <BR>" ;
$telephone = substr($tel[1], 0, 10);
if($telephone == "-</td>") { NULL; } else { $telephone = substr($tel[1], 0, 10); }
// Organisateur
$organisateur = @eregi('<tr style="font-weight: bold; background: #FFFFFF; font-size: 12px;">
<td style="color: #a2141e; width: 150px; padding-left: 5px;">Organisée par : </td>
<td>(.*)</td>
</tr>
<tr style="font-weight: bold; background: #E8E8E8; font-size: 12px;">
<td style="color: #a2141e; padding-left: 5px;">Contact téléphone : </td>',$page,$who);
echo "$who[1] <BR>" ;
addslashes($who[1]);
// Exposants
$exposants = @eregi('<tr style="font-weight: bold; background: #FFFFFF; font-size: 12px;">
<td style="color: #a2141e; padding-left: 5px;">Nombre d\'exposants : </td>
<td>(.*)</td>
</tr>
<tr style="font-weight: bold; background: #E8E8E8; font-size: 12px;">
<td style="color: #a2141e; padding-left: 5px;">Type d\'exposant : </td>',$page,$exposant);
echo "$exposant[1] <BR>" ;
addslashes($exposant[1]);
// rue
$rues = @eregi('<tr style="font-weight: bold; background: #FFFFFF; font-size: 12px;">
<td style="color: #a2141e; padding-left: 5px;">Précision lieu : </td>
<td>(.*) </tr>
<tr style="font-weight: bold; background: #E8E8E8; font-size: 12px;">
<td style="color: #a2141e; padding-left: 5px;">Horaire : </td>',$page,$rue);
echo " RUE: $rue[1] <BR>" ;
addslashes($rue[1]);
$nom_du_lieu = addslashes($rue[1]);;
// Horraire
$horaire = @eregi('<tr style="font-weight: bold; background: #E8E8E8; font-size: 12px;">
<td style="color: #a2141e; padding-left: 5px;">Horaire : </td>
<td>(.*)</td>
</tr>
<tr style="font-weight: bold; background: #FFFFFF; font-size: 12px;">
<td style="color: #a2141e; padding-left: 5px;">Nombre d\'exposants : </td>',$page,$time);
//echo "$time[1] <br><br><br>" ;
// On attribut le département en fonction des 2 premiers chiffre du code postal
$horaire_debut = substr($time[1], 0, 50);
echo $horaire_debut .'<br>';
// si il n y a pas de date de fin alors je lui attribue la date de début
if (empty($horaire_debut)) {
$horaire_debut = NULL;
} else {
$horaire_debut = $horaire_debut;
}
// On attribut le département en fonction des 2 premiers chiffre du code postal
$horaire_fin = substr($time[1], 7, 10);
echo $horaire_fin .'<br>';
// si il n y a pas de date de fin alors je lui attribue la date de début
if (empty($horaire_fin)) {
$horaire_fin = NULL;
} else {
$horaire_fin = $horaire_fin;
}
$id++ ; // $id = On parcourt tous les id
echo '**************************************<br>';
$region = regionIdByDepartement($departement);
// Attribution de la valeur id 1010 pour la fnac
$id_simply_user = '34';
// On valide la sortie par default
$valide = '1';
// On valide la sortie par default
$price = 'Non renseigné';
// On valide la sortie par default
$photo = NULL;
// On valide la sortie par default
$id_type_loisirs = '4';
// description
$desc_genre = $pieces[1] .' à '.$lieu[1]. ' ;
$description = addslashes($desc_genre);
// Pseudo libre
$sql = "INSERT INTO `table` (id_simply_user,titre,price,photo,date_debut_sortie,horaire_debut,date_fin_sortie,horaire_fin,description,phone,street,postcode,city,id_region,id_departements,id_type_loisirs,valide) VALUES ('$id_simply_user','$nom_evenement','$price','$photo','$date_debut', '$time[1]', '$date_debut', '$horaire_fin', '$description','$telephone','$nom_du_lieu','$codepostal','$nom_ville','$region','$departement','$id_type_loisirs','$valide')";
$req = mysql_query($sql) or die('Erreur SQL !'.$sql.'<br>'.mysql_error());
echo 'Insertion en bdd';
}
?>
Salut à tous.
J'ai un ptit bout de code qui permet d'intégrer des données dans une base de donnée tout marche très bien en local mais pas en ligne ....
[php]/****** FONCTIONS ******/
function suppr_accents($string) {
return str_replace( array('à','á','â','ã','ä', 'ç', 'è','é','ê','ë', 'ì','í','î','ï', 'ñ', 'ò','ó','ô','õ','ö', 'ù','ú','û','ü', 'ý','ÿ', 'À','Á','Â','Ã','Ä', 'Ç', 'È','É','Ê','Ë', 'Ì','Í','Î','Ï', 'Ñ', 'Ò','Ó','Ô','Õ','Ö', 'Ù','Ú','Û','Ü', 'Ý'), array('a','a','a','a','a', 'c', 'e','e','e','e', 'i','i','i','i', 'n', 'o','o','o','o','o', 'u','u','u','u', 'y','y', 'A','A','A','A','A', 'C', 'E','E','E','E', 'I','I','I','I', 'N', 'O','O','O','O','O', 'U','U','U','U', 'Y'), $string);
}
//set_time_limit(0);
// On défini les id à parcourir
$id = 98000 ;
while ($id < 98005) {
$adresse = "http://www.lesite_$id.php" ; // adresse de la page à exploiter
$page = @file_get_contents ($adresse); // récupérer le contenu de la page
echo 'id :' .$id;
// Titre
$titre = @eregi('<h1>(.*)</h1>',$page,$nom);
// explode sur le titre pour ne récupèrer que le type
$pieces = explode(" - ", $nom[1]);
echo "$pieces[1] <BR>" ;
$nom_evenement = addslashes($pieces[1]);
// Date
$date = @eregi('<tr style="font-weight: bold; background: #FFFFFF; font-size: 12px;">
<td style="color: #a2141e; width: 150px; padding-left: 5px;">Date : </td>
<td>(.*)</td>
</tr>
<tr style="font-weight: bold; background: #E8E8E8; font-size: 12px;">
<td style="color: #a2141e; width: 150px; padding-left: 5px;">Lieu : </td>',$page,$event);
// Traitement de la date ( conversion de type texte en format sql )
$texte_original="$event[1]";
$jourmois_fr = array('janvier', 'fevrier', 'mars', 'avril', 'mai', 'juin', 'juillet', 'aout', 'septembre', 'octobre', 'novembre', 'decembre', 'lundi ', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche');
$jourmois_en = array('january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday');
$timestamp=strtotime(str_replace($jourmois_fr, $jourmois_en, strtolower(suppr_accents($texte_original))));
$date_debut = date("Y-m-d", $timestamp);
echo $date_debut .'<br>';
// Ville
$ville = @eregi('<tr style="font-weight: bold; background: #E8E8E8; font-size: 12px;">
<td style="color: #a2141e; width: 150px; padding-left: 5px;">Lieu : </td>
<td>(.*)</td>
</tr>
<tr style="font-weight: bold; background: #FFFFFF; font-size: 12px;">
<td style="color: #a2141e; padding-left: 5px;">Précision lieu : </td>',$page,$lieu);
echo "$lieu[1] <BR>" ;
$nom_ville = addslashes($lieu[1]);
// on crée la requête SQL
$sql = "SELECT cp FROM `cp_autocomplete` WHERE `ville` LIKE '".addslashes($lieu[1])."' ORDER BY cp DESC LIMIT 0, 1 ";
// on envoie la requête
$req = mysql_query($sql);
// on fait une boucle qui va faire un tour pour chaque enregistrement
while($data = mysql_fetch_assoc($req))
{
// on affiche les informations de l'enregistrement en cours
echo $data['cp'] .'<br><br>' ;
// On attribut le département en fonction des 2 premiers chiffre du code postal
$departement = substr($data['cp'], 0, 2);
$codepostal = substr($data['cp'], 0, 5);
echo 'département' .$departement. '<br><br>';
}
// Téléphone
$phone = @eregi('<tr style="font-weight: bold; background: #E8E8E8; font-size: 12px;">
<td style="color: #a2141e; padding-left: 5px;">Contact téléphone : </td>
<td>(.*)</tr>
<tr style="font-weight: bold; background: #FFFFFF; font-size: 12px;">
<td style="color: #a2141e; padding-left: 5px;">Contact email : </td>',$page,$tel);
echo "$tel[1] <BR>" ;
$telephone = substr($tel[1], 0, 10);
if($telephone == "-</td>") { NULL; } else { $telephone = substr($tel[1], 0, 10); }
// Organisateur
$organisateur = @eregi('<tr style="font-weight: bold; background: #FFFFFF; font-size: 12px;">
<td style="color: #a2141e; width: 150px; padding-left: 5px;">Organisée par : </td>
<td>(.*)</td>
</tr>
<tr style="font-weight: bold; background: #E8E8E8; font-size: 12px;">
<td style="color: #a2141e; padding-left: 5px;">Contact téléphone : </td>',$page,$who);
echo "$who[1] <BR>" ;
addslashes($who[1]);
// Exposants
$exposants = @eregi('<tr style="font-weight: bold; background: #FFFFFF; font-size: 12px;">
<td style="color: #a2141e; padding-left: 5px;">Nombre d\'exposants : </td>
<td>(.*)</td>
</tr>
<tr style="font-weight: bold; background: #E8E8E8; font-size: 12px;">
<td style="color: #a2141e; padding-left: 5px;">Type d\'exposant : </td>',$page,$exposant);
echo "$exposant[1] <BR>" ;
addslashes($exposant[1]);
// rue
$rues = @eregi('<tr style="font-weight: bold; background: #FFFFFF; font-size: 12px;">
<td style="color: #a2141e; padding-left: 5px;">Précision lieu : </td>
<td>(.*) </tr>
<tr style="font-weight: bold; background: #E8E8E8; font-size: 12px;">
<td style="color: #a2141e; padding-left: 5px;">Horaire : </td>',$page,$rue);
echo " RUE: $rue[1] <BR>" ;
addslashes($rue[1]);
$nom_du_lieu = addslashes($rue[1]);;
// Horraire
$horaire = @eregi('<tr style="font-weight: bold; background: #E8E8E8; font-size: 12px;">
<td style="color: #a2141e; padding-left: 5px;">Horaire : </td>
<td>(.*)</td>
</tr>
<tr style="font-weight: bold; background: #FFFFFF; font-size: 12px;">
<td style="color: #a2141e; padding-left: 5px;">Nombre d\'exposants : </td>',$page,$time);
//echo "$time[1] <br><br><br>" ;
// On attribut le département en fonction des 2 premiers chiffre du code postal
$horaire_debut = substr($time[1], 0, 50);
echo $horaire_debut .'<br>';
// si il n y a pas de date de fin alors je lui attribue la date de début
if (empty($horaire_debut)) {
$horaire_debut = NULL;
} else {
$horaire_debut = $horaire_debut;
}
// On attribut le département en fonction des 2 premiers chiffre du code postal
$horaire_fin = substr($time[1], 7, 10);
echo $horaire_fin .'<br>';
// si il n y a pas de date de fin alors je lui attribue la date de début
if (empty($horaire_fin)) {
$horaire_fin = NULL;
} else {
$horaire_fin = $horaire_fin;
}
$id++ ; // $id = On parcourt tous les id
echo '**************************************<br>';
$region = regionIdByDepartement($departement);
// Attribution de la valeur id 1010 pour la fnac
$id_simply_user = '34';
// On valide la sortie par default
$valide = '1';
// On valide la sortie par default
$price = 'Non renseigné';
// On valide la sortie par default
$photo = NULL;
// On valide la sortie par default
$id_type_loisirs = '4';
// description
$desc_genre = $pieces[1] .' à '.$lieu[1]. ' ;
$description = addslashes($desc_genre);
// Pseudo libre
$sql = "INSERT INTO `table` (id_simply_user,titre,price,photo,date_debut_sortie,horaire_debut,date_fin_sortie,horaire_fin,description,phone,street,postcode,city,id_region,id_departements,id_type_loisirs,valide) VALUES ('$id_simply_user','$nom_evenement','$price','$photo','$date_debut', '$time[1]', '$date_debut', '$horaire_fin', '$description','$telephone','$nom_du_lieu','$codepostal','$nom_ville','$region','$departement','$id_type_loisirs','$valide')";
$req = mysql_query($sql) or die('Erreur SQL !'.$sql.'<br>'.mysql_error());
echo 'Insertion en bdd';
}
?>[/php]