我正在尝试使用 Walmart API 来显示有关产品的一些信息。
\n\nAPI 返回一个 json 对象,我将其转换为常规数组,并且只是使用 echo 来显示此数据。
\n\n问题是,当我从 API 获取longDescription变量时,它包含 HTML - 这很好,但它没有被渲染,而是将其全部显示为纯文本。这是我的代码:
echo "<p id=\'longDescription\'>";\n echo $obj[\'longDescription\'];\necho "</p>";\nRun Code Online (Sandbox Code Playgroud)\n\n这是$obj[\'longDescription\']变量中包含的内容:
<br><b>HP 15-ay039wm 15.6" Laptop:</b><br><br><b>Key Features and Benefits:</b>\n<ul>\n <li>15.6" Display<br>HD (1366 x 768) SVA Brightview WLED-backlit Display<br><br></li>\n <li>Intel Core i3-6100U Dual-Core Processor<br>2.3GHz<br><br></li>\n <li>8GB system memory<br>Gives you the power to handle most power-hungry applications and tons of multimedia work<br><br></li>\n <li>1TB Hard Drive<br>Store 666,000 photos, 285,000 songs or 526 hours of …Run Code Online (Sandbox Code Playgroud) 如何让我的代码只显示文件夹的链接而不是目录中的文件?
$d = dir(".");
echo "<ul>";
while(false !== ($entry = $d->read())) {
echo "<li><a href='{$entry}'>{$entry}</a></li>";
}
echo "</ul>";
$d->close();
Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个与服务器进行一些交互的 Discord 机器人。
我已经编写了一些有效的代码,但是它存在一个大问题。这是我的代码:
if (command === "file") {
var accusor = message.author.id;
var username = args[0];
var reason = args[1];
var punishment = args[2];
var duration = args[3];
if(!duration) duration = "N/A";
console.log("Returning last " + amount + " for " + username);
request.post({url:'http://grumpycrouton.com/kismet/api/post_complaint.php', form: {accusor:accusor,search:username,reason:reason,punishment:punishment,duration:duration}}, function(err,httpResponse,body) {
message.reply(body);
});
}
Run Code Online (Sandbox Code Playgroud)
命令是!file {playername} {reason} {punishment} {duration},但问题是,有时一些变量可能有多个单词。例如,{reason}可能是“玩家过得不好”之类的内容,但由于参数的拆分方式,我的代码无法正确解析它。
假设输入了这个命令:
!file GrumpyCrouton "Player had a bad time" Kick "1 Day"
但是参数实际上会以不同的方式展开,因为第三个参数中有空格,但正则表达式将所有参数按空格分开,而不考虑引号。基本上,Discord 忽略引号并将每个单词用作它自己的参数,从而使{punishment}和{duration}的参数索引为 6 和 …
我正在尝试将 HTML 输入元素与 一起使用type="time",但得到了意想不到的结果。我在一页上有两个,其中一个有效,一个无效。
<td>
<input type="time" class="uk-input" value="7:30:00" name="timein[]"/>
</td>
<td>
<input type="time" class="uk-input" value="16:00:00" name="timeout[]"/>
</td>Run Code Online (Sandbox Code Playgroud)
第一个元素将呈现为空白,为什么?
我有以下代码,它循环遍历机器上的所有视频输入设备,并应显示该输入设备的流。
$.each(devices, function( index, value ) {
if(value.kind == 'videoinput') {
console.log(value);
navigator.mediaDevices.getUserMedia({video: { exact: value.deviceId }}).then(function(stream) {
console.log(stream);
var video = document.createElement('video');
video.srcObject = stream;
video.autoplay = true;
var elem = '\
<div>\
<div class="view_camera_' + index + ' uk-card uk-card-default uk-card-body uk-card-small"></div>\
</div>\
';
outputs.append(elem);
$('.view_camera_' + index).append(video);
}).catch(function(err) {
console.log(err);
});
}
});
Run Code Online (Sandbox Code Playgroud)
请注意,在我的选择器中,我使用了{video: { exact: value.deviceId }},根据文档,它应该“需要特定的相机”。
我最初使用的{ video: { deviceId: value.deviceId } }实际上是按照我想要的方式工作的,但文档说“上面的[使用 deviceId 而不是确切的]将返回您请求的相机,或者如果该特定相机不再可用,则返回另一个相机”。我不希望它“如果特定相机不再可用,则返回不同的相机”,因此我转而使用关键字exact。 …
我有以下代码,它应该在去除所有空格后比较 2 个字符串,这是该函数的简化版本:
\n\nfunction not_same($type, $org_str1, $str2) {\n\n $str1 = preg_replace(\'/\\s+/\', \'\', $org_str1);\n $str2 = preg_replace(\'/\\s+/\', \'\', $str2);\n\n $tries = [];\n $tries[] = ["str1" => $str1, "str2" => $str2, "encoded1" => urlencode($str1), "encoded2" => urlencode($str2)]; \n\n if($str1 == $str2) {\n return true;\n } else {\n return false;\n }\n\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我正在使用它来检查计算机上的处理器是否与我的数据库中的匹配型号相同,$org_str1我的客户说它正在运行的计算机上的处理器也是如此,并且$str2该模型应该在我的数据库中使用CPU有。
有时这些字符串具有不需要的空格,因此在比较过程中我删除了所有空格,以便比较文本本身。
\n\n现在我收到计算机回复说CPU有问题,因为没有匹配,因为有一些空白没有被删除。
\n\n在这种特定情况下,我尝试比较字符串 Client:Celeron\xc2\xae N3050与 Server: Celeron\xc2\xae N3050。\n我每次都会记录服务器上实际比较的内容,在我的客户端上它说它正在比较 Client:Celeron\xc2\xae N3050比较的内容,在我的客户端上它说它正在比较 Client:与 Server:Celeron\xc2\xaeN3050
我尝试将这个空格复制并粘贴到str_replace() …
php ×3
html ×2
directory ×1
discord.js ×1
getusermedia ×1
javascript ×1
node.js ×1
preg-replace ×1
scandir ×1
whitespace ×1