从XML站点地图生成器中删除php扩展

时间:2012-07-02 21:59:34

标签: php mysql xml sitemap

我的开发人员出去度假,我正在试图弄清楚如何从我的XML站点地图生成器中删除php扩展。

以下是需要更改的代码:

    //remaining main pages:
$pages=array();
$query="SELECT DISTINCT strona FROM `sites_table`";
if($result=$GLOBALS['mysql']->query($query))
{
    $i=0;
    while($row=$result->fetch_assoc())
    {
        if($row['site']!="/index.php")
        {
            $pageName=substr($row['site'],1);
            array_push($pages,$pageName);
            write(insertIntoTemplate($pageName,"0.8","hourly"));
        }
    }
    $result->free();
}
else 
    echo $dbErrorMsg;

MySQL查询只打印网站数组,如:news.php,sports.php,politics.php等。

我只需删除此.php扩展名;)我已经使用特殊的.htaccess文件执行了该操作,但现在我需要通知Google我使用的是非.php网站。

3 个答案:

答案 0 :(得分:0)

看起来您应该可以更改该行:

$pageName=substr($row['site'],1);

为:

$pageName=substr($row['site'],1, -4);

注意:所有这些代码都删除了最后四个字符 - 如果有预期扩展名的地方,不遵循.php模型的项目等,这可能会破坏网站的其他部分。

答案 1 :(得分:0)

这应该对你有用,只要你可以用空字符串替换所有出现的.php。这不会考虑您的应用程序中可能存在的任何边缘情况,如果您不确定自己,您需要与开发人员交谈以确定这一点。

//remaining main pages:
$pages=array();
$query="SELECT DISTINCT strona FROM `sites_table`";
if($result=$GLOBALS['mysql']->query($query))
{
    $i=0;
    while($row=$result->fetch_assoc())
    {
        if($row['site']!="/index.php")
        {
            //do a string replace of all occurrences of .php 
            $pageName=substr(str_replace('.php','',$row['site']),1);
            array_push($pages,$pageName);
            write(insertIntoTemplate($pageName,"0.8","hourly"));
        }
    }
    $result->free();
}
else 
    echo $dbErrorMsg;

答案 2 :(得分:0)

似乎$ pageName也用于其他一些页面,所以我就这样做了,现在没有错误:

            //do a string replace of all occurrences of .php 
            $pageName=substr($row['site'],1);
            array_push($pages,$pageName);
            $pageName2=substr(str_replace('.php','',$row['site']),1);
            array_push($pages,$pageName);
            write(insertIntoTemplate($pageName2,"0.8","hourly"));
相关问题