Ver Mensaje Individual
  #3 (permalink)  
Antiguo 18/07/2015, 12:04
mblascog
 
Fecha de Ingreso: enero-2002
Ubicación: Sabadell
Mensajes: 565
Antigüedad: 22 años, 2 meses
Puntos: 4
Respuesta: Dos scripts en uno

Buenas,
No duplico la etiqueta <html>

El primer script es este. Al final, incluye sitemap.xml y es donde se produce el error:

Código PHP:
Ver original
  1. <!DOCTYPE html>
  2. <html lang="es">
  3. <?php
  4.     // BBDD
  5.     include("includes/inc_conexion.php");
  6.     include("includes/inc_config.php");
  7.        
  8.     $xml_file = 'fincamps_HS/500190_UN.XML';
  9.     if (file_exists($xml_file)) {
  10.         $xml = simplexml_load_file($xml_file);
  11.         $borra_tabla = mysql_query("delete from t_un") or die(mysql_error());
  12.         $borra_table = mysql_query("delete from t_fotos") or die (mysql_error());
  13.     }
  14.     else
  15.         exit("Error a l'intentar obrir el fitxer ".$xml_file);
  16.  
  17.     foreach ($xml->Registro as $Registro) {  
  18.         $estado= addslashes(utf8_decode($Registro->Seleccionado));
  19.         $qry = "INSERT INTO t_un "."( id_piso, referencia, operacion, tipo, familia, poblacion, situacion1, situacion2, precio, habitaciones, metros, estado, CodigoPostal, DireccionInmueble, AbreviacionTipoCalle, NombreCalleInmueble, AbreviacionTipoNumero, NumeroCalleInmueble, CertificacionEnergetica, PrestacionEnergetica, CertificacionEmisiones, PrestacionEmisiones, Moll_box, Grua_box)".
  20.             " VALUES ('$Registro->IdPiso', "."'".addslashes($Registro->Expediente)."', ".
  21.                 "'".addslashes($Registro->IdTipoOperacion)."', "."'".addslashes($Registro->IdTipoInmueble)."', ".
  22.                 "'".addslashes($Registro->IdFamiliaTipoInmueble)."', "."'".addslashes($Registro->IdPoblacion)."', ".
  23.                 "'".addslashes($Registro->Situacion1)."', "."'".addslashes($Registro->Situacion2)."', ".
  24.                 "'".addslashes($Registro->PrecioEur)."', ".
  25.                 "'".addslashes($Registro->Hdobles_num+$Registro->Hsimples_num)."', ".
  26.                 "'".addslashes($Registro->SuperficieTotal)."', "."".$estado.", ".
  27.                 "'".addslashes($Registro->CodigoPostal)."', "."'".addslashes($Registro->DireccionInmueble)."', ".
  28.                 "'".addslashes($Registro->AbreviacionTipoCalle)."', "."'".addslashes($Registro->NombreCalleInmueble)."', ".
  29.                 "'".addslashes($Registro->AbreviacionTipoNumero)."', "."'".addslashes($Registro->NumeroCalleInmueble)."', ".
  30.                 "'".addslashes($Registro->CertificacionEnergetica)."', "."'".addslashes($Registro->PrestacionEnergetica)."', ".
  31.                 "'".addslashes($Registro->CertificacionEmisiones)."', "."'".addslashes($Registro->PrestacionEmisiones)."', ".
  32.                 "'".addslashes($Registro->Muelle_box)."', "."'".addslashes($Registro->Grua_box)."'".")";
  33.         $result = mysql_query($qry) or die(mysql_error());
  34.         // canviar a php.ini: php_value max_execution_time 90 i posar 30
  35.         if ($Registro->Foto1 != "") {
  36.             $qry = "INSERT INTO t_fotos (referencia, foto) VALUES ('".addslashes($Registro->Expediente)."', '".addslashes($Registro->Foto1)."')";
  37.             $result = mysql_query($qry) or die(mysql_error());
  38.         }
  39.         if ($Registro->Foto2 != "") {
  40.             $qry = "INSERT INTO t_fotos (referencia, foto) VALUES ('".addslashes($Registro->Expediente)."', '".addslashes($Registro->Foto2)."')";
  41.             $result = mysql_query($qry) or die(mysql_error());
  42.         }
  43.         if ($Registro->Foto3 != "") {
  44.             $qry = "INSERT INTO t_fotos (referencia, foto) VALUES ('".addslashes($Registro->Expediente)."', '".addslashes($Registro->Foto3)."')";
  45.             $result = mysql_query($qry) or die(mysql_error());
  46.         }
  47.         if ($Registro->Foto4 != "") {
  48.             $qry = "INSERT INTO t_fotos (referencia, foto) VALUES ('".addslashes($Registro->Expediente)."', '".addslashes($Registro->Foto4)."')";
  49.             $result = mysql_query($qry) or die(mysql_error());
  50.         }
  51.         if ($Registro->Foto5 != "") {
  52.             $qry = "INSERT INTO t_fotos (referencia, foto) VALUES ('".addslashes($Registro->Expediente)."', '".addslashes($Registro->Foto5)."')";
  53.             $result = mysql_query($qry) or die(mysql_error());
  54.         }
  55.         if ($Registro->Foto6 != "") {
  56.             $qry = "INSERT INTO t_fotos (referencia, foto) VALUES ('".addslashes($Registro->Expediente)."', '".addslashes($Registro->Foto6)."')";
  57.             $result = mysql_query($qry) or die(mysql_error());
  58.         }
  59.         if ($Registro->Foto7 != "") {
  60.             $qry = "INSERT INTO t_fotos (referencia, foto) VALUES ('".addslashes($Registro->Expediente)."', '".addslashes($Registro->Foto7)."')";
  61.             $result = mysql_query($qry) or die(mysql_error());
  62.         }
  63.         if ($Registro->Foto8 != "") {
  64.             $qry = "INSERT INTO t_fotos (referencia, foto) VALUES ('".addslashes($Registro->Expediente)."', '".addslashes($Registro->Foto8)."')";
  65.             $result = mysql_query($qry) or die(mysql_error());
  66.         }
  67.         if ($Registro->Foto9 != "") {
  68.             $qry = "INSERT INTO t_fotos (referencia, foto) VALUES ('".addslashes($Registro->Expediente)."', '".addslashes($Registro->Foto9)."')";
  69.             $result = mysql_query($qry) or die(mysql_error());
  70.         }
  71.         if ($Registro->Foto10 != "") {
  72.             $qry = "INSERT INTO t_fotos (referencia, foto) VALUES ('".addslashes($Registro->Expediente)."', '".addslashes($Registro->Foto10)."')";
  73.             $result = mysql_query($qry) or die(mysql_error());
  74.         }
  75.     }
  76.     echo "Un".'<br>';
  77.        
  78. ?>
  79.  
  80. </html>
  81.  
  82.  
  83. <?php   include("sitemap.php");  
  84.     mysql_close($connexion);
  85. ?>

Y el segundo script, sitemap.xml es este:

Código PHP:
Ver original
  1. <?php
  2.     header('Content-Type: application/xml');
  3.  
  4.     function eliminaAccentos($String)
  5.     {
  6.         $String = str_replace("[äáàâãª]","a",$String);
  7.         $String = str_replace("[ÁÀÂÃÄ]","A",$String);
  8.         $String = str_replace("[ÍÌÎÏ]","I",$String);
  9.         $String = str_replace("[íìîï]","i",$String);
  10.         $String = str_replace("[éèêë]","e",$String);
  11.         $String = str_replace("[ÉÈÊË]","E",$String);
  12.         $String = str_replace("[óòôõöº]","o",$String);
  13.         $String = str_replace("[ÓÒÔÕÖ]","O",$String);
  14.         $String = str_replace("[úùûü]","u",$String);
  15.         $String = str_replace("[ÚÙÛÜ]","U",$String);
  16.         $String = str_replace("[^´`¨~]","",$String);
  17.         $String = str_replace("ç","c",$String);
  18.         $String = str_replace("Ç","C",$String);
  19.         $String = str_replace("ñ","n",$String);
  20.         $String = str_replace("Ñ","N",$String);
  21.         $String = str_replace(" ","-",$String);
  22.         return $String;
  23.    
  24.     }
  25.    
  26.    
  27.     $codigo = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
  28.     $codigo .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">'."\n";
  29.  
  30.     $codigo .= '<url><loc>http://xxxx.es/</loc></url>'."\n";
  31.     $codigo .= '<url><loc>http://xxxx.es/inmuebles-singulares</loc></url>'."\n";
  32.    
  33.     $consulta = "SELECT t_un.tipo, t_un.operacion, t_tipo.nombre_tipo_es, t_tipo.nombre_tipo_ca, t_operacion.operacion_tipo_es, t_poblacion.nombre_poblacion, t_un.situacion1, t_un.referencia ".
  34.             "FROM t_un, t_operacion, t_tipo, t_poblacion ".
  35.             "WHERE t_un.operacion = t_operacion.id_operacion AND t_un.tipo = t_tipo.id_tipo AND t_un.poblacion = t_poblacion.id_poblacion ".
  36.             "ORDER BY t_un.familia, t_un.tipo, t_un.operacion, t_un.poblacion";
  37.     $qConsulta = mysql_query($consulta);
  38.     $registros = mysql_num_rows($qConsulta);
  39.     if ($registros > 0){
  40.         while ($fila = mysql_fetch_assoc($qConsulta)) {
  41.             $pagina_ca = "<url><loc>http://xxxx.es/";
  42.             $pagina_es = "<url><loc>http://xxxx.es/";
  43.             switch ($fila['tipo']) {
  44.                 case 3:
  45.                     $pagina_ca .= 'pisos-cases/';
  46.                     $pagina_es .= 'pisos-casas/';
  47.                     break;
  48.                 case 4:
  49.                     $pagina_ca .= 'pisos-cases/';
  50.                     $pagina_es .= 'pisos-casas/';
  51.                     break;
  52.                 case 5:
  53.                     $pagina_ca .= 'solars-parceles/';
  54.                     $pagina_es .= 'solares-parcelas/';
  55.                     break;
  56.                 case 6:
  57.                     $pagina_ca .= 'naus-industrials/';
  58.                     $pagina_es .= 'naves-industriales/';
  59.                     break;
  60.                 case 7:
  61.                     $pagina_ca .= 'locals-oficines/';
  62.                     $pagina_es .= 'locales-oficinas/';
  63.                     break;
  64.                 case 8:
  65.                     $pagina_ca .= 'parquings/';
  66.                     $pagina_es .= 'parkings/';
  67.                     break;
  68.                 case 9:
  69.                     $pagina_ca .= 'immobles-singulars/';
  70.                     $pagina_es .= 'inmuebles-singulares/';
  71.                     break;
  72.                 case 0:
  73.                     $pagina_ca .= 'oportunitats-bancaries/';
  74.                     $pagina_es .= 'oportunidades-bancarias/';
  75.                     break;
  76.             }
  77.             if ($fila['operacion'] == 3) {
  78.                 $pagina_ca .= "lloguer/".trim(strtolower($fila['nombre_tipo_ca']))."-en-lloguer-";
  79.                 $pagina_es .= "alquiler/".trim(strtolower($fila['nombre_tipo_es']))."-en-alquiler-";
  80.             }
  81.             else {         
  82.                 $pagina_ca .= "venda/".trim(strtolower(eliminaAccentos($fila['nombre_tipo_ca'])))."-en-venda-";
  83.                 $pagina_es .= "venta/".trim(strtolower(eliminaAccentos($fila['nombre_tipo_es'])))."-en-venta-";
  84.             }
  85.             $pagina_ca .= eliminaAccentos(strtolower($fila['nombre_poblacion']));
  86.             $pagina_es .= eliminaAccentos(strtolower($fila['nombre_poblacion']));
  87.             if ($fila['situacion1'] != '') {
  88.                 $pagina_ca .= '-'.eliminaAccentos(strtolower(trim($fila['situacion1'])));
  89.                 $pagina_es .= '-'.eliminaAccentos(strtolower(trim($fila['situacion1'])));
  90.             }
  91.             $pagina_ca .= '-'.$fila['referencia'].'.html'.'</loc></url>'."\n";
  92.             $pagina_es .= '-'.$fila['referencia'].'.html'.'</loc></url>'."\n";
  93.            
  94.             $codigogo .= $pagina_ca.$pagina_es;
  95.         }
  96.     }
  97.     $codigogo .= "</urlset>";
  98.  
  99.     if ($fitxer = fopen("sitemap.xml", "w+")) {
  100.         fwrite($fitxer, $codigogo);
  101.         fclose($fitxer);
  102.     }
  103.     else
  104.         echo "error";
  105. ?>

Gracias
__________________
Qué fácil cuando lo sabes y qué difícil cuando no