简体   繁体   English

在php的html标记内使用const Array

[英]Using const Array inside html tags in php

const EMOJI = [
    ":lol" => "http://localhost/chat/emoji/0046.gif",
    ":D" => "http://localhost/chat/emoji/0055.gif"
]

i want to use 我想用

EMOJI[:lol] EMOJI [:哈哈]

in src can anybody tell me how should i use it ? 在src中有人可以告诉我如何使用它吗?

case ":lol":
    echo "<img src='EMOJI[:lol]' width='32' height='32'>";
break;

You have to escape quotes here. 您必须在此处转义报价。 You can use like this: 您可以这样使用:

echo "<img src='".EMOJI[':lol']."' width='32' height='32'>";

就像这样:

echo "<img src='" . EMOJI[':lol'] . "' width='32' height='32'>";

Array key should be integer or string so you should use EMOJI[':lol'] instead of EMOJI[:lol] ; 数组键应为整数或字符串,因此应使用EMOJI[':lol']代替EMOJI[:lol]

Example

case ":lol":
    echo "<img src='".EMOJI[':lol']."' width='32' height='32'>";
break;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM