【问题标题】:Syntax Error in concat echo statement and html codeconcat echo 语句和 html 代码中的语法错误
【发布时间】:2014-11-05 04:15:05
【问题描述】:

请帮助我理解以下 concat 的语法

我想在 echo 中使用以下代码来理解连接

1--> <div class="alert echo $_REQUEST['error_id'];?>"\>

我尝试以下代码,但出现语法错误,有两个回显..

2-->echo "<div class=\"alert" . echo $_REQUEST['error_id']; . "\">";

错误是我无法得到它...和i want two answer都使用single quotedouble quote

编辑

感谢@Rizier123 现在它可以工作了,但是 css 不能正常工作,因为我在 calss="alert"

中申请了

在使用以下代码时,它工作正常 <div class="alert echo $_REQUEST['error_id'];?>"\>

但是在应用您的代码后它不起作用..只有文本出现但背景颜色没有出现,并且边界也消失了,如下所示

类名alert显示登录状态..

编辑

再次感谢,我只是忘记在班级名称后加空格..

【问题讨论】:

  • 你的css类的名字是什么?

标签: php html css concatenation


【解决方案1】:

你不需要再写echo;了!

所以这应该有效:

//echo with double quotes
echo "<div class=\"alert" . $_REQUEST['error_id'] . "\">";        

//echo with single quotes
echo '<div class="alert' . $_REQUEST['error_id'] . '">';       

如果你的类名包含空格,也许你需要添加一个空格!(..."alert"...)

【讨论】:

    【解决方案2】:

    试试这个

    echo '<div class=\"alert"' .  $_REQUEST['error_id'] . '">';
    

    【讨论】:

      【解决方案3】:

      两种方法都可以

      1. HTML 中的 PHP

      <div class="alert<?php echo $_REQUEST['error_id'];?>">
      

      2。 PHP 中的 HTML

      echo "<div class='alert". $_REQUEST['error_id'] ."'>";
      

      或者你也可以这样做

      echo "<div class=\"alert". $_REQUEST['error_id'] ."\">";
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-06-11
        • 1970-01-01
        相关资源
        最近更新 更多