如何用字符串链接php变量?

时间:2011-10-18 16:59:59

标签: php string url concatenation

  $fullurl=$_SERVER['PATH_INFO'];
  if(isset($_POST['name']) && isset($_POST['login']) && isset($_POST['pass']))
  {   

            echo '
              <form action=".'$fullurl'." method="POST"/>
              <table width="1000" border="1" cellpadding="10" id="navigationBar">
                  <tr>
                    <td> <a href="/PoliticalForum/controlPanel.php">Control Panel</a></td>
                    <td> <a href="/PoliticalForum/checkEmail.php">Donate</a> </td>
                    <td> <a href="/PoliticalForum/mainHome.php">Logout</a> </td>
                  </tr>
               </table>
            ';
  }
  else
  { 

        echo '
          <form action=".'$fullurl'." method="POST"/>
          <table width="1000" border="1" cellpadding="10" id="navigationBar">
              <tr>
                <td> <a href="/PoliticalForum/Registration.php">Register</a></td>
                <td> <a href="/PoliticalForum/controlPanel.php">Control Panel</a></td>
                <td> <a href="/PoliticalForum/checkEmail.php">Donate</a> </td>
                <td align="right">name:<input name="name" type="text" /></td>
                <td>password:<input name="pass" type="text" /> <input name="login" type="submit" value="Login" /> </td>
              </tr>
           </table>
           ';
  }

我希望将相同的网址传递给操作,但它给了我一个错误:

  

解析错误:语法错误,意外T_VARIABLE,期待','或';'在第9行的C:\ xampp \ htdocs \ PoliticalForum \ headerSite.php

并且$ fullurl还会给我当前页面的网址吗?

5 个答案:

答案 0 :(得分:2)

替换

<form action=".'$fullurl'." method="POST"/>

<form action="' . $fullurl .'" method="POST"/>

答案 1 :(得分:1)

您已交换了连接运算符和单引号:

echo '<form action="'.$fullurl.'" … ';

答案 2 :(得分:0)

当您输出表单时,变量$fullurl周围有单引号...只需删除它们就可以了,

echo '
  <form action="' . $fullurl . '" method="POST"/>
  etc...

答案 3 :(得分:0)

将两条<form />行更改为:

<form action="'.$fullurl.'" method="POST"/>

你的单引号位于错误的位置。

$_SERVER['PATH_INFO']将包含域之后的所有内容,因此如果它是http://domain.com/something/else,则它将包含/ something / else。

http://php.net/manual/en/reserved.variables.server.php

答案 4 :(得分:0)

<?php
 $fullurl=$_SERVER['PATH_INFO'];
 if(isset($_POST['name']) && isset($_POST['login']) && isset($_POST['pass']))
 {   

        echo '
          <form action="' . $fullurl . '" method="POST"/>
          <table width="1000" border="1" cellpadding="10" id="navigationBar">
              <tr>
                <td> <a href="/PoliticalForum/controlPanel.php">Control Panel</a></td>
                <td> <a href="/PoliticalForum/checkEmail.php">Donate</a> </td>
                <td> <a href="/PoliticalForum/mainHome.php">Logout</a> </td>
              </tr>
           </table>
        ';
}
else
{ 

    echo '
      <form action="' . $fullurl . '" method="POST"/>
      <table width="1000" border="1" cellpadding="10" id="navigationBar">
          <tr>
            <td> <a href="/PoliticalForum/Registration.php">Register</a></td>
            <td> <a href="/PoliticalForum/controlPanel.php">Control Panel</a></td>
            <td> <a href="/PoliticalForum/checkEmail.php">Donate</a> </td>
            <td align="right">name:<input name="name" type="text" /></td>
            <td>password:<input name="pass" type="text" /> <input name="login" type="submit" value="Login" /> </td>
          </tr>
       </table>
       ';
}