【问题标题】:Variables inside href don't work as intended [duplicate]href 中的变量无法按预期工作[重复]
【发布时间】:2017-10-11 16:11:39
【问题描述】:

我创建了一个函数来创建一个表。
该功能本身运行良好,但我想要一个指向另一个页面的链接。
在该页面中,我使用 GET 变量,因此它们需要进入 URL。
我得到了:

$calendar.= '<div class="day-number"><a href="http://localhost/PHPOrdner/Calendar/Day.php?inputmonth='$inputMonth'&inputyear='$inputYear'&day='$list_day'"></a>'.$list_day.'</div>';

但这不起作用:

解析错误:语法错误,意外的“$inputMonth”(T_VARIABLE) 在...

我试图逃避'喜欢:.../Day.php?inputmonth=\'$inputMonth\'...
但这在我的 URL 中给了我“.../Day.php?inputmonth=%27$inputMonth%27...”,所以我需要变量的代码不起作用。

使用&lt;?php echo "..."; ?&gt; 也不起作用。
我还是新手,还有其他方法吗?

【问题讨论】:

  • 你不能只在字符串旁边放一个变量,你可以concatenate他们。
  • 不要miser 添加更多. 点来连接字符串。
  • 我不知道原因是字符串连接,否则我不会问。我很抱歉重复。

标签: php html


【解决方案1】:

你缺少.

$calendar = '<div class="day-number"><a href="http://localhost/PHPOrdner/Calendar/Day.php?inputmonth='.$inputMonth.'&inputyear='.$inputYear.'&day='.$list_day.'"></a>'.$list_day.'</div>';

【讨论】:

    【解决方案2】:

    你的字符串连接错误你忘记了.

    试试:

    $calendar.= '<div class="day-number"><a href="http://localhost/PHPOrdner/Calendar/Day.php?inputmonth='.$inputMonth.'&inputyear='.$inputYear.'&day='.$list_day.'></a>'.$list_day.'</div>';
    

    【讨论】:

      猜你喜欢
      • 2020-04-23
      • 2013-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-18
      • 1970-01-01
      相关资源
      最近更新 更多