我收到以下错误"警告:file_get_contents无法打开流:HTTP请求失败!HTTP/1.0 400错误请求",同时点击"http://Google.com"
<?php
$content = file_get_contents("http://www.google.com");
if (strpos($http_response_header[0], "200")) {
echo "SUCCESS";
}
else {
echo "FAILED";
}
?>
Run Code Online (Sandbox Code Playgroud)
因为这个问题,我无法解析URL.我正在使用WAMP(Apache Version-2.2.22,PHP 5.4.3版).
采取的步骤: - 1.allow_url_fopen在php.ini中启用2.Tried编码URL 3.Even Used Curl php函数遇到同样的问题.4.允许防火墙
请帮忙.
我有很多变量,我想确保它们不等于某个值.
if($post[0] !== "-" && $post[3] !== "-" && $post[8] !== "-" ...) {
// code to be executed
}
Run Code Online (Sandbox Code Playgroud)
功能似乎是最聪明的解决方案,有些类似:
function check_var($junk_value, $array) {
foreach($array as $arr) {
if($arr[$key]) == $junk_value) {
return false;
}
else {
return true;
}
}
}
$junk_value = "-";
$array = array($post[0], $post[3], $post[8], $hello);
check_var($junk_value, $array);
Run Code Online (Sandbox Code Playgroud)
我对foreach循环不是很好,我不知道其他人是如何使用"$ key"的,但它输出的是它没有为我设置.我一直想知道人们如何在没有定义它们的情况下使用"$ key"和"$ value"变量.
编辑:我在这个问题上吸收了很多信息.在10分钟内,我觉得我知道的更多.谢谢你的所有答案.
嗨,我正在使用ajax进行国家,州,城市的三重下拉,参考链接是:http://roshanbh.com.np/2008/01/populate-triple-drop-down-list-change-options- value-from-database-using-ajax-and-php.html.它成功地工作但我需要如果一个状态在db表中没有城市然后出现一个新的文本框,输入的值存储在php mysql中.什么编码我实现了.请提出一些想法.
码:
阿贾克斯:
<script language="javascript" type="text/javascript">
function getXMLHTTP() {
var xmlhttp = false;
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e1) {
xmlhttp = false;
}
}
}
return xmlhttp;
}
function getState(countryId) {
var strURL = "findState.php?country=" + countryId;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function () {
if …Run Code Online (Sandbox Code Playgroud) 我想在屏幕中央打开一个div(水平和垂直).
var documnetWidth = $(document).width(),
documentHeight = $(document).height(),
widgetFormHeight = widgetForm.height(),
widgetFormWidth = widgetForm.width();
widgetForm.css({
top: documentHeight / 2 - widgetFormHeight / 2,
left: documnetWidth / 2 - widgetFormWidth / 2
});
Run Code Online (Sandbox Code Playgroud)
我的小部件是水平中心,但垂直方向需要一些偏移.
这是我第一次使用jQuery.我正在加载一个大的背景图像,当它加载时,我在三秒钟内褪色.此脚本适用于Firefox和Chrome,但不适用于IE(当然!).是否有任何失败的安全方式使它在IE中神奇地工作,是否有一些更漂亮的写作方式?
<div class="bgImage" />
Run Code Online (Sandbox Code Playgroud)
$(document).ready(function () {
// add bg image and fade
var _image = new Image();
_image.id = 'newImageId';
_image.src = "./css/background.jpg";
$(_image).load(function () {
$('div.bgImage').css('background-image', 'url(./css/background.jpg)');
$('div.bgImage').fadeTo(3000, 1);
});
});
Run Code Online (Sandbox Code Playgroud) 我有两个途径/emails和/eamils/:id:
var createRouter = function() {
var router = express.Router();
router.route('/emails/:id').get((req, res) => {
console.log('get=>/emails/id');
});
router.route('/emails').get((req, res) => {
console.log('get> /emails');
});
return router;
}
Run Code Online (Sandbox Code Playgroud)
每当发送下一个请求时,第二个处理程序都会被调用:
GET http://localhost:4000/rest-api/emails/?id=59
Run Code Online (Sandbox Code Playgroud)
带id参数的第一个从不起作用.我怎样才能解决这个问题?
我正在按字母顺序过滤表并遇到问题.我不明白x.innerHTML > y.innerHTML这段代码中的概念:
table = document.getElementById('myTable');
rows = table.getElementsByTagName('tr');
x = rows[1].getElementsByTagName('td')[0];
y = rows[2].getElementsByTagName('td')[0];
//check if the two rows should switch place:
console.log(x.innerHTML.length, y.innerHTML.length);
console.log(x.innerHTML > y.innerHTML);
Run Code Online (Sandbox Code Playgroud)
它是如何工作的?
我有以下哈希数组:
persons = [
{name: 'Mark', age: 28},
{name: 'John', age: 45},
{name: 'Sam', age: 34},
{name: 'John', age: 34}
]
Run Code Online (Sandbox Code Playgroud)
我想获取 key 的唯一值数组name。在这种情况下应该是['Mark', 'John', 'Sam'].
这是我的解决方案:
names = []
persons.each do |person|
names << person[:name] unless names.include? person[:name]
end
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来做到这一点?
我有下一个错误:
Traceback (most recent call last):
File "DungeonGame.py", line 92, in <module>
possible = possibleMoves(locations["player"])
File "DungeonGame.py", line 65, in possibleMoves
if player[0][0] == 0:
TypeError: 'int' object is not subscriptable
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
def possibleMoves(player):
options = ["RIGHT", "LEFT", "UP", "DOWN"]
if player[0][0] == 0:
options.remove("LEFT")
elif player[0][0] == 4:
options.remove("RIGHT")
elif player[0][1] == 0:
options.remove("DOWN")
elif player[0][1] == 4:
options.remove("UP")
return options
...
locations = {"monster" : (1, 2), "door" : (3, 2), "player" : (4, 1)}
possible = possibleMoves(locations["player"]) …Run Code Online (Sandbox Code Playgroud) 我有一个字符串数组:
names = ['log_index', 'new_index']
Run Code Online (Sandbox Code Playgroud)
我要做的是从名称创建变量:
names.each { |name| name = [] } # obviously it does not do what I want
Run Code Online (Sandbox Code Playgroud)
这些变量不会在代码中的任何位置之前声明。
我该怎么办?