gpt4 book ai didi

php - 第 1 行第 3 列错误 : xmlParsePI : no target name

转载 作者:行者123 更新时间:2023-11-28 02:31:10 25 4
gpt4 key购买 nike

我需要为我的在线商店的 cms、产品、图像和类别页面生成一个动态 xml。在这里,我向您展示我使用的 3 个文件。第一个是文件 funciones.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;
}?>

文件 funciones_cms.php :

<?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 但它不起作用:

    <? 
header("Content-Type: text/xml;charset=iso-8859-1");
echo '<?xml version="1.0" encoding="UTF-8"?>';
include ("../funciones/funciones_cms.php");
include ("../funciones/funciones.php");
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<?php echo generar_sitemap() ?>
</urlset>

我需要为我的在线商店的 cms、产品、图像和类别页面生成一个动态 xml。你能帮帮我吗?

最佳答案

  1. 您的“cms.xml”未被网络服务器解析为 PHP
  2. HTTP 客户端接收 PHP 源
  3. PHP 源不是有效的 XML
  4. 客户端中的 XML 解析器抛出错误

如果将文件命名为 cms.xml Web 服务器不会将其作为 PHP 执行(至少在没有特殊配置的情况下不会)。这意味着 PHP 源将被发送到 HTTP 客户端。这包括 <?在文件顶部启动您的 PHP 源代码。

<?在 XML 中用于 processing instructions (简称 PI),但它们需要目标名称,如 <?xml-stylesheet ...?>

关于php - 第 1 行第 3 列错误 : xmlParsePI : no target name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50672205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com