在一个三元PHP脚本中,如何将第二个变量连接到我的字符串中?

3

Before style="style="color: ' . $rx_event_colors . '" I want to add the $ima variable. it's just a variable with an image inside of the string. Additionally, if you think i would benefit from just adding the

 if(!empty($ins_event))
            {
            echo "<tr><td>&nbsp; <a href='". matry::here(array('event_id'=>$ins_event['id'])) . "'" . 
            ( $ins_event['status'] == 2 ? ' style="color: ' . $rx_event_colors . '">Completed Insurance Event' : '>Active Insurance Event') . "</a></td></tr>";     

            }

I've tried:

? ' $ima, style="style="color: ' . $rx_event_colors . '"
                      style="style="color: ' . $ima, $rx_event_colors . '"
                      style="style="color: ' . ($ima), $rx_event_colors . '"
                      style="style="color: ' . ($ima), ($rx_event_colors) . '"

with no avail.


2
在 PHP 中的连接符中使用“.”(点号),而不是“,”(逗号)。 - user557846
1
你为什么这么着急使用三元运算符呢?如果代码变得难以理解和调试,那就毫无意义了。 - Philip Whitehouse
1个回答

3

我假设$ima是一个字符串。要连接字符串,请使用“.”

因此,在三元运算符的第一部分中,如果您想添加$ima,只需执行以下操作:

' style="color: ' . $ima . $rx_event_colors . '">Completed Insurance Event'

然而,当你说“[$ima]只是一个带有图像的字符串变量”时,我感到困惑。如果是这样,$ima包含图像本身的路径吗?如果是这样,它应该属于img标签的SRC属性,而不是STYLE属性内部。
更新: 因为$ima包含整个img标签,所以它不属于style属性。请看:
' style="color: ' . $rx_event_colors . '">' . $ima . 'Completed Insurance Event'

你能提供一下 $ima 变量中确切的内容示例吗? - Sites Done Right
$ima = "<img src='/flet/check-icon.gif'>"; - Head
哦!**$ima变量包含整个img标签。如果是这种情况,那么您不能将$ima**放置在另一个标签的属性中。 - Sites Done Right
1
我相信你想要做的是在修饰文字之前添加图像(作为某种项目符号)。尝试这样做: ' style="color: ' . $rx_event_colors . '">' . $ima . '已完成保险事件'这样,**$ima** 就在你正在修饰的 a 标签内部,而不是在其样式属性内部。 - Sites Done Right
它有效了。将其标记为答案,我会给你支票。非常感谢。'style="color: ' . $rx_event_colors . '">' . $ima . '已完成保险事件' : '>活动保险事件') - Head
显示剩余2条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接