我需要为我的在线商店的cms,产品,图片和类别页面生成动态xml。在这里,我向您展示我使用的3个文件。第一个是文件funciones.php:
city1
文件funciones_cms.php:
<?php
function devolver_url ($v,$i,$tipo=1)
{
foreach ($v as $linea)
{
$b=explode ("#",$linea);
if ($b[1]==$i)
$retorno=$b[2];
}
return $retorno;
}
function devolver_url_productos ($v,$i)
{
foreach ($v as $linea)
{
$b=explode ("#",$linea);
if ($b[1]==$i)
$retorno=$b[2]."/".$b[4]."-".$b[3].".html";
}
return $retorno;
}
function consultar_bd($consulta)
{
$bd="XXXXXXX";
$clave="XXXXXXXXX";
$host="localhost:3306";
$conexion = mysql_connect($host, $user, $clave);
mysql_select_db($bd, $conexion);
$resultado = mysql_query($consulta, $conexion) or die(mysql_error());
return $resultado;
}
function quitar_tildes($cadena)
{
$no_permitidas= array ("á","é","í","ó","ú","Á","É","Í","Ó","Ú","ñ","À","Ã","Ì","Ò","Ù","Ù","à ","è","ì","ò","ù","ç","Ç","â","ê","î","ô","û","Â","Ê","ÃŽ","Ô","Û","ü","ö","Ö","ï","ä","«","Ò","Ã","Ä","Ë");
$permitidas= array ("a","e","i","o","u","A","E","I","O","U","n","N","A","E","I","O","U","a","e","i","o","u","c","C","a","e","i","o","u","A","E","I","O","U","u","o","O","i","a","e","U","I","A","E");
$texto = str_replace($no_permitidas, $permitidas ,$cadena);
return $texto;
}?>
最后我需要创建文件cms.xml但它不起作用:
<?php
include ("funciones.php");
function poner_url_cms ($v)
{
$dominio="https://www.mobiliariocomercialmaniquies.com/";
$l=array("nada","en","fr","es","de","it","ca");
foreach ($v as $a)
{
$b=explode ("#",$a);
echo '
<url>
<loc>'.$dominio.$l[$b[1]].'/content/'.$b[0].'-'.$b[2].'</loc>
';
for ($i=1;$i<7;$i++)
{
if ($i<>$b[1])
{
echo '<xhtml:link
rel="alternate"
';
echo 'hreflang="'.$l[$i].'"
';
echo 'href="'.$dominio.$l[$i].'/content/'.$b[0].'-'.devolver_url($v,$i,1).'"
/>';
}
}
echo '</url>
';
}
}
function generar_sitemap()
{
$consulta= "SELECT id_lang, id_cms,link_rewrite FROM ps_cms_lang";
$resultado = consultar_bd($consulta);
$filas = mysql_num_rows($resultado);
$cms=0;
if ($filas > 0)
{
while ($r= mysql_fetch_assoc($resultado))
{
if ( ($r['link_rewrite']<>"") && ($r['id_lang']<7) )
{
if ($r['id_cms']==$cms)
{
$v[]=$cms."#".$r['id_lang']."#".$r['link_rewrite'];
}
else
{
if ($cms==0)
{
unset($v);
$cms=$r['id_cms'];
$v[0]=$cms."#".$r['id_lang']."#".$r['link_rewrite'];
}
else
{
poner_url_cms($v);
unset($v);
$cms=$r['id_cms'];
$v[0]=$cms."#".$r['id_lang']."#".$r['link_rewrite'];
}
}
}
}
poner_url_cms($v);
}
}
?>
我需要为我的在线商店的cms,产品,图片和类别页面生成动态xml。你能帮帮我吗?
答案 0 :(得分:0)
如果您将文件命名为cms.xml
,则Web服务器将不会将其作为PHP执行(至少在没有特殊配置的情况下)。这意味着PHP源将被发送到HTTP客户端。这包括在文件顶部启动PHP源的<?
。
<?
用于processing instructions(短PI),但它们需要目标名称,如<?xml-stylesheet ...?>