【问题标题】:Set as String From HTML and PHP Line of Code从 HTML 和 PHP 代码行设置为字符串
【发布时间】:2013-07-12 11:02:09
【问题描述】:

我坚持在html中创建一行代码,并结合php作为完整的字符串

我想把字符串放到一个变量中,以便它可以被 php 回显

原始html + php语法:

   <a href="JavaScript:newPopup('<?php echo $site_path; ?>/transactions/details.php?id=<?php echo $r['idtr_inventory']; ?>');"><i class="icon-info-sign"></i></a>

我将该行代码分配给某个 var,例如:$myVar

我试过这个:

$myVar= "<a href='JavaScript:newPopup('<?php echo ".(string)$site_path; ."?>/transactions/details.php?id=<?php echo ". (string)$r['idtr_inventory']; . "?>');'><i class='icon-info-sign'></i></a>";

但仍然有错误。有没有什么合适的方法可以让这行代码完全可以字符串化?

谢谢。

【问题讨论】:

  • 对于包含更多引号的字符串,您可以使用 php HEREDOC

标签: php string type-conversion


【解决方案1】:

应该是这样的:

// you dont need to put the php tag while initializing a variable with string + value of another variable
$myVar= "<a href=\"JavaScript:newPopup('".$site_path."/transactions/details.php?id=". $r['idtr_inventory']."');\"><i class='icon-info-sign'></i></a>";

我希望这能有所帮助。

【讨论】:

  • 嗨,saran,语法中缺少它自己的变量,因此没有显示像“idtr_inventory”这样的id。只是 ...details.php?id=。现在已经解决了。但是感谢您的评论
【解决方案2】:

使用 PHP HEREDOC 作为:

$foo = <<<EOT
<some markup and php variables>
EOT;

【讨论】:

  • 嗨 lekhnath,这仍然给我错误,但感谢您的评论。我自己解决了这个问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-09-02
  • 2023-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多