提问者:小点点

为php上的html按钮分配几个css类


我正试图给php上的html按钮分配几个css类,但当浏览器看到空间时,它关闭类。

我想做什么

$html = '<span class=' .'btn-sub btn-sub2'. '>' . $caption[0] . '</span>'; 

结果

<span class="btn-sub" btn-sub2="">New</span>

共1个答案

匿名用户

您的引用有误:

// this is the same
$html = '<span class=' .'btn-sub btn-sub2'. '>' . $caption[0] . '</span>';
// as this:
$html = '<span class=btn-sub btn-sub2>' . $caption[0] . '</span>';

然后将其解析为在答案中显示的内容。属性(例如classid)后面的空格表示“new attribute”

// What you want is this:
$html = '<span class="btn-sub btn-sub2">' . $caption[0] . '</span>';

您正在做一些有创意的事情,停止/继续将字符串添加在一起,而您所需要的只是双引号。供参考:

echo 'a' . 'b' . 'c'; // -> 'abc'

相关问题