为什么我的脚本输出一个结束和公牛;( • ) 以及删除它的最佳方法是什么


Why does my script output an end • ( • ) and what is the best way to remove it?

我为一个网站编写了这个"你在这里"脚本并且它正在工作,但是故事类别的输出有一个额外的尾随公牛,我想知道为什么并删除 •

<?php
if (isset($_GET['pagina']) && isset($_GET['storycategory'])) {
$pagina = $_GET['pagina'];
$storycategory = $_GET['storycategory'];
$storypage = $storycategory;
$storypage = str_replace(stories, story, $storypage);
$storypagename = $_GET[$storypage];
$content_path = 'You are here: Home &bull; ' . $pagina . ' &bull; ' . $storycategory . ' &bull; ' . $storypagename;
$content_path = str_replace("-", " ", $content_path);
echo '<strong>' . $content_path . '</strong><hr />'; // Voor een bezoeker die in een bepaald verhaal bezoekt - Output: You are here: Home • all stories • story category Name • Best story ever
}
elseif (isset($_GET['pagina']) && isset($_GET['storycategory'])) { // this is the part that has a trailing  •  that I'd like to remove and find out why it was created by my script
    $pagina = $_GET['pagina'];
    $storycategory = $_GET['storycategory'];
    $content_path = 'You are here: Home &bull; ' . $pagina . ' &bull; ' . $storycategory; // Note: I did NOT add a  •  here but it is generated in output...
    $content_path = str_replace("-", " ", $content_path);
    echo '<strong>' . $content_path . '</strong><hr />'; // Voor een bezoeker die in een bepaalde alles uit deze story category pagina is! Output: You are here: Home You are here: Home • all stories • story category Name • 
    }
    elseif (isset($_GET['pagina'])) {
        $pagina = $_GET['pagina'];
        $content_path = 'You are here: Home &bull; ' . $pagina;
        $content_path = str_replace("-", " ", $content_path);
        echo '<strong>' . $content_path . '</strong><hr />'; // Voor een bezoeker die op de alle sex stories pagina is! Output: Home • all stories
        }
        else {
            // Als iemand verdwaald is en daardoor bovenstaande totaal niet van toepassing is...
            echo '<strong>Thank you for visiting our site!</strong><hr />';
            }
            ?>
Pagina很好,没有尾随公牛,但是当我访问任何类别时,

都会有一个我不喜欢出现的•(请参阅代码中的注释输出和注释),但是当我访问任何类别中的任何故事页面时,最后没有•...

我应该如何移除公牛,为什么会生成公牛?

感谢您的阅读!

编辑我想解释一下我的代码中使用的变量,希望它有助于理解这个问题。

我有一些网址,想告诉访问者他们在哪里:

故事页面:www.example.com/index.php?pagina=all-stories&storycategory=the-best-stories&the-best-story=my-first-computer

"最佳故事"中所有故事的页面:www.example.com/index.php?pagina=all-stories&storycategory=the-best-stories

所有故事类别的页面:www.example.com/index.php?pagina=all-stories

我有一个名为pagina的文件夹,在这个文件夹中,您会找到一个名为storycategory的文件夹,在文件夹

storycategory中,您会发现大量的文件夹,所有这些文件夹的名称的最后一部分都有故事,并且很多php文件在结尾处有故事(名称相同,但将故事更改为故事类别中php文件的故事)在故事类别文件夹内的文件夹中是我的故事存储..

第 1 部分呼应"你在这里:主页 • 所有故事 • 最好的故事 • 我的第一台电脑"这工作得很好

        if (isset($_GET['pagina']) && isset($_GET['storycategory']) && isset($_GET['storycategory'])) {
$pagina = $_GET['pagina'];
$storycategory = $_GET['storycategory'];
$storypage = $storycategory;
$storypage = str_replace(stories, story, $storypage);
$storypagename = $_GET[$storypage];
$content_path = 'You are here: Home &bull; ' . $pagina . ' &bull; ' . $storycategory . ' &bull; ' . $storypagename;
$content_path = str_replace("-", " ", $content_path);
echo '<strong>' . $content_path . '</strong><hr />'; // Voor een bezoeker die in een bepaald verhaal bezoekt - Output: You are here: Home • all stories • story category Name • Best story ever
}

第 2 部分 不需要的地方出了问题 •

    elseif (isset($_GET['pagina']) && isset($_GET['storycategory'])) { // this is the part that has a trailing  •  that I'd like to remove and find out why it was created by my script
$pagina = $_GET['pagina'];
$storycategory = $_GET['storycategory'];
$content_path = 'You are here: Home &bull; ' . $pagina . ' &bull; ' . $storycategory; // Note: I did NOT add a  •  here but it is generated in output...
$content_path = str_replace("-", " ", $content_path);
echo '<strong>' . $content_path . '</strong><hr />'; // Voor een bezoeker die in een bepaalde alles uit deze story category pagina is! Output: You are here: Home You are here: Home • all stories • story category Name • 
}

第 3 部分也很好,没有问题

    elseif (isset($_GET['pagina'])) {
    $pagina = $_GET['pagina'];
    $content_path = 'You are here: Home &bull; ' . $pagina;
    $content_path = str_replace("-", " ", $content_path);
    echo '<strong>' . $content_path . '</strong><hr />'; // Voor een bezoeker die op de alle sex stories pagina is! Output: Home • all stories
    }

我的代码的第 4 部分是其他部分,用于未设置与故事相关的变量或未知错误

    else {
        // Als iemand verdwaald is en daardoor bovenstaande totaal niet van toepassing is...
        echo '<strong>Thank you for visiting our site!</strong><hr />';
        }

第 2 部分有什么问题,或者为什么我在最后得到公牛?

编辑 2已编辑第 2 行取代if (isset($_GET['pagina']) && isset($_GET['storycategory']) && isset($_GET['storycategory'])) {跟if (isset($_GET['pagina']) && isset($_GET['storycategory'])) {

最后 • 的问题仍然存在于故事类别页面上,$storypage用于使用 str_replace 从storycategory创建$storypagename,而 Home 是硬编码的。

编辑 3(已解决) isset($_GET[$storypagename]))(第 2 行)和$storypagename = $_GET[$storypagename];确实解决了 srories 全局文件中的问题,但是任何变量都必须在请求之前定义,就像我之前在评论中所说的那样,所以我必须找到一种方法在第 2 行之前定义$storypagename。我在每个页面的所有元标记文件中都定义了它,这工作得很好。

注意:最后 2 个粗体部分动态的,因此如果访问者属于任何其他类别,最后一个 url 变量将更改。故事页面:www.example.com/index.php?pagina=all-stories&storycategory=the-best-stories&最好的故事=我的第一台计算机此类别中的故事页面: www.example.com/index.php?pagina=all-stories&storycategory=the-best-stories所有故事类别的页面:www.example.com/index.php?pagina=all-stories

首先,我尝试使用故事类别值使用 str_replace(),但我之前无法定义它,所以它从未奏效,我相信元标记文件中的一小行额外$storypagename = 'the-best-story';是最好的解决方案

我的网站有 1000 个页面,所以array()是没有选择的,每个页面都有一个元标记 php 文件并在此脚本之前加载,我在那里定义了 $storypagename 变量以确保在请求之前定义它。 这个解决方案使PHP代码更小。

我想对 mudasobwaKonstantina 说声谢谢,这两个答案都有助于找到这种方法来解决此错误。所有 3 个部分现在都工作正常,再次感谢!最终工作代码

    <?php 
    if (isset($_GET['pagina']) && isset($_GET['storycategory']) && isset($_GET[$storypagename])) {
    $pagina = $_GET['pagina'];
    $storycategory = $_GET['storycategory'];
    $storypagename = $_GET[$storypagename];
    $content_path = 'You are here: Home &bull; ' . $pagina . ' &bull; ' . $storycategory . ' &bull; ' . $storypagename;
    $content_path = str_replace("-", " ", $content_path);
    echo '<strong>' . $content_path . '</strong><hr />'; // Voor een bezoeker die in een bepaald verhaal bezoekt - Output: You are here: Home • all stories • story category Name • Best story ever
    }
    elseif (isset($_GET['pagina']) && isset($_GET['storycategory'])) { // this is the part that has a trailing  •  that I'd like to remove and find out why it was created by my script
$pagina = $_GET['pagina'];
$storycategory = $_GET['storycategory'];
$content_path = 'You are here: Home &bull; ' . $pagina . ' &bull; ' . $storycategory;  // Note: I did NOT add a  •  here but it is generated in output...
$content_path = str_replace("-", " ", $content_path);
echo '<strong>' . $content_path . '</strong><hr />'; // Voor een bezoeker die in een bepaalde alles uit deze story category pagina is! Output: You are here: Home You are here: Home • all stories • story category Name • 
}
    elseif (isset($_GET['pagina'])) {
    $pagina = $_GET['pagina'];
    $content_path = 'You are here: Home &bull; ' . $pagina;
    $content_path = str_replace("-", " ", $content_path);
    echo '<strong>' . $content_path . '</strong><hr />'; // Voor een bezoeker die op de alle sex stories pagina is! Output: Home • all stories
    }
    else {
        // Als iemand verdwaald is en daardoor bovenstaande totaal niet van toepassing is...
        echo '<strong>Thank you for visiting our site!</strong><hr />';
               }
               ?>

您错误地复制粘贴了第一个if条件:

if (
  isset($_GET['pagina']) && 
  isset($_GET['storycategory']) && 
  isset($_GET['storycategory'])) { // ERROR, should be $_GET['storypagename']

然后您用空$storypagename输入它.

是否正在计算$storypagename,都应在此处进行计算和检查,因为此条件可能始终true,并且您永远不会输入else if部分。

正如 mudasobwa 所说:因为你的第一个条件有错误(在第 2 行)

if (isset($_GET['pagina']) && isset($_GET['storycategory']) && isset($_GET['storycategory'])) {

您永远不会输入第一个elseif块(在第 12 行)

执行的行是第 8 行:

$content_path = 'You are here: Home &bull; ' . $pagina . ' &bull; ' . $storycategory . ' &bull; ' . $storypagename;

但是$storypagename是空的。 所以你最后会得到一颗子弹