【问题标题】:Troubleshooting "parse error, unexpected '>'" error [closed]解决“解析错误,意外'>'”错误[关闭]
【发布时间】:2011-09-24 08:49:27
【问题描述】:

我收到这个正在读取的错误

解析错误:解析错误,第 11 行 C:\wamp\www\about.php 中出现意外的 '>'

这是我的代码:

<?php
session_start();
include ("include/header.php");
if (!isset($_SESSION['name'])){;
header("Location:includeindex.php");
exit;
 }
 else{
TopNavigation("about Me -ECA236","About Me",$_SESSION['name']);
echo "<p>Here is a little about me. I am a mother of twin girls who are 9 </p>
echo "<p>I been married for 5 years but been with my husband for 11 years </p>
echo "<p>I am attending college for Computer Programming and Database Mangament      </p>
echo "<p>After I get done with this degree I am want to go back for Web Design </p>
echo "<p>since half my classes are web design now. I enjoy camping,bon fires and </p>
echo "<p>playing video games, hanging out with friends and family.</p>
Footer();
   }
 ?>

我已尝试添加 ;到最后和“到最后,但弹出相同的内容。有人可以看到我做错了什么。

这是我在末尾添加“;”时遇到的错误:

警告:include(include/header.php) [function.include]:无法打开流:第 3 行的 C:\wamp\www\about.php 中没有这样的文件或目录

警告:include() [function.include]:在 C:\wamp\www\about.php 中打开 'include/header.php' 以包含 (include_path='.;C:\php5\pear') 失败在第 3 行

警告:无法修改标头信息 - 标头已由第 5 行 C:\wamp\www\about.php 中的(输出开始于 C:\wamp\www\about.php:3)发送

【问题讨论】:

  • 像这样使用echo "&lt;p&gt;Here is a little about me. I am a mother of twin girls who are 9 &lt;/p&gt;";
  • 您是否尝试以正确的顺序将 both 放在最后?
  • 您不需要使用 echo 来输出更大的 HTML 块。关闭 PHP,输出 HTML,然后再次打开 PHP。请参阅下面的答案以获取示例。
  • 正如@hakre 所说,关闭 PHP。如果您必须在 PHP 模式下执行此操作,请至少使用专为多行字符串设计的 HEREDOC:php.net/heredoc
  • @Marc B:单引号和双引号字符串也是多行的。

标签: php


【解决方案1】:

你有:

echo "<p>playing video games, hanging out with friends and family.</p>

你需要:

echo "<p>playing video games, hanging out with friends and family.</p>";

【讨论】:

  • 或者下一行的echo " 是多余的,在所有输出的末尾只缺少一个";
  • 我做了那个修复,我得到另一个错误
  • 我已经做了所有这些,但我得到了新的错误。
【解决方案2】:

您需要在 echo 行的末尾添加引号 ";

【讨论】:

  • 虽然技术上不正确(看起来),但这不是错误 - 它只是添加了一个空白语句作为 if 块的第一条语句。奇怪,但不会抛出错误。
  • 确实如此,但不会导致代码中断。这是一个有效的空语句。
【解决方案3】:

每个回显行的末尾都需要一个引号和一个分号。

一般来说,每当您在 PHP 中打开一行报价时,您还需要关闭它,并且每一行(除了少数例外,例如流控制语句等)都需要以分号结尾。

【讨论】:

    【解决方案4】:

    你没有关闭引号:

    回声“

    这里是关于我的一点。我是 9 个 " 的双胞胎女孩的母亲;

    【讨论】:

    • 我这样做了,我得到另一个错误
    • 您遇到的新错误是什么?
    • 警告:include(include/header.php) [function.include]:未能打开流:第 3 行的 C:\wamp\www\about.php 中没有此类文件或目录警告: include() [function.include]:在第 3 行的 C:\wamp\www\about.php 中打开 'include/header.php' 以包含 (include_path='.;C:\php5\pear') 失败警告:无法修改标头信息 - 标头已由第 5 行 C:\wamp\www\about.php 中的(输出从 C:\wamp\www\about.php:3 开始)发送
    • include 文件夹下是否有header.php 文件?
    • include ("includes/header.php"); header("位置:includeindex.php");是我所拥有的
    【解决方案5】:

    所有回声线都需要关闭它们的语音标记并以分号结尾。

    【讨论】:

      【解决方案6】:

      试试这个:

      session_start();
      include_once ("include/header.php");
      if (!isset($_SESSION['name'])) {
          header("Location:includeindex.php");
          exit;
      }
      else {
          TopNavigation("about Me -ECA236", "About Me", $_SESSION['name']);
          echo "<p>Here is a little about me. I am a mother of twin girls who are 9</p>";
          echo "<p>I been married for 5 years but been with my husband for 11 years</p>";
          echo "<p>I am attending college for Computer Programming and Database Mangament</p>";
          echo "<p>After I get done with this degree I am want to go back for Web Design</p>";
          echo "<p>since half my classes are web design now. I enjoy camping,bon fires and</p>";
          echo "<p>playing video games, hanging out with friends and family.</p>";
          Footer();
      }
      

      【讨论】:

        【解决方案7】:

        您的文件的语法错误。下面的示例应该可以修复它,但是,该消息仅表示您的输出的一部分确实是代码,因为您错过了正确使用字符串周围的 " 引号。请记住,字符串也适用于多行,所以这可能更容易理解:

        <?php
        session_start();
        include ("include/header.php");
        if (!isset($_SESSION['name']))
        {
          header("Location:includeindex.php");
          exit;
        } else {
          TopNavigation("about Me -ECA236","About Me",$_SESSION['name']);
          echo "
            <p>Here is a little about me. I am a mother of twin girls who are 9 </p>
            <p>I been married for 5 years but been with my husband for 11 years </p>
            <p>I am attending college for Computer Programming and Database Mangament      </p>
            <p>After I get done with this degree I am want to go back for Web Design </p>
            <p>since half my classes are web design now. I enjoy camping,bon fires and </p>
            <p>playing video games, hanging out with friends and family.</p>
            " # string ends here
            ;
          Footer();
        }
        ?>
        

        或者更好,因为这是 PHP:

        <?php
        session_start();
        include ("include/header.php");
        if (!isset($_SESSION['name']))
        {
          header("Location:includeindex.php");
          exit;
        } else {
          TopNavigation("about Me -ECA236","About Me",$_SESSION['name']);
          ?>
            <p>Here is a little about me. I am a mother of twin girls who are 9 </p>
            <p>I been married for 5 years but been with my husband for 11 years </p>
            <p>I am attending college for Computer Programming and Database Mangament</p>
            <p>After I get done with this degree I am want to go back for Web Design </p>
            <p>since half my classes are web design now. I enjoy camping,bon fires and </p>
            <p>playing video games, hanging out with friends and family.</p>
          <?php
          Footer();
        }
        ?>
        

        【讨论】:

        • 我现在收到这些错误警告:include(include/header.php) [function.include]:无法打开流:C:\wamp\www\about 中没有这样的文件或目录。第 3 行的 php 警告:include() [function.include]:在 C:\wamp\www\about 中打开 'include/header.php' 以包含 (include_path='.;C:\php5\pear') 失败。第 3 行的 php 警告:无法修改标头信息 - 第 6 行 C:\wamp\www\about.php 中的标头已由(输出开始于 C:\wamp\www\about.php:3)发送
        • 文件include/header.php在哪个路径?如果您想知道 include 的作用以及错误消息的含义,请查看 php.net/manual/en/function.include.php
        【解决方案8】:

        就像其他人所说的那样,您需要引号和分号。但这也忽略了这样做的方法更少冗长(并且开销更少)。例如,您可以在一个 echo 语句下完成所有操作:

        echo"
          <p>>Here is a little about me. I am a mother of twin girls who are 9</p>
          <p>I been married for 5 years but been with my husband for 11 years</p>
          <p>I am attending college for Computer Programming and Database Mangament</p>
        ";
        

        或者,另一种方法是

        $content = " <<<END
          <p>Here is a little about me. I am a mother of twin girls who are 9</p>
          <p>I been married for 5 years but been with my husband for 11 years</p>
          <p>I am attending college for Computer Programming and Database Mangament</p>
        END;
        
        echo $content;
        

        如果您要执行大量非 PHP 操作,最好的解决方案就是关闭 PHP 标记并使用直接 HTML 执行此操作,您完全不必担心引号和分号!

        ?>
          <p>Here is a little about me. I am a mother of twin girls who are 9</p>
          <p>I been married for 5 years but been with my husband for 11 years</p>
          <p>I am attending college for Computer Programming and Database Mangament</p>
        <?php
        

        我的意思是,我在 SO 示例中看到了很多 &lt;?php&gt;&lt;/php&gt; 重复以及大量 echo 重复。它有效吗?当然。但这是不必要的。它会减慢你的速度,并创造更多搞砸的机会。而且,简直丑到不行!我不想调试它!

        【讨论】:

          【解决方案9】:

          您根本没有关闭任何 echo 语句。以下应该可以工作:

          <?php
          session_start();
          include ("include/header.php");
          if (!isset($_SESSION['name'])){
          header("Location:includeindex.php");
          exit;
           }
           else{
          TopNavigation("about Me -ECA236","About Me",$_SESSION['name']);
          echo "<p>Here is a little about me. I am a mother of twin girls who are 9 </p>";
          echo "<p>I been married for 5 years but been with my husband for 11 years </p>";
          echo "<p>I am attending college for Computer Programming and Database Mangament      </p>";
          echo "<p>After I get done with this degree I am want to go back for Web Design </p>";
          echo "<p>since half my classes are web design now. I enjoy camping,bon fires and </p>";
          echo "<p>playing video games, hanging out with friends and family.</p>";
          Footer();
             }
           ?>
          

          我还在第 4 行看到了一个我认为不需要的分号 - 在上面删除了它。

          【讨论】:

          • 在所有其他行上仍然需要分号。
          • 如果您的意思是我在第一次发布后意识到并在之后添加这些的回声语句。
          • 为什么在第一个 if 语句后面加分号?
          • 我说我不相信它是必要的。不过,我会从我的答案中删除它。
          猜你喜欢
          • 2018-01-08
          • 2014-04-02
          • 2011-10-26
          • 2014-09-02
          • 2014-04-26
          • 2013-10-02
          • 2023-04-09
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多