好吧,所以我试图为facebookapi输入一个动态元标记,一些事情正在发生。
以下是我获取值的方法
$id = $_GET['id'];
$id = intval($id);
这就是我输入的地方。
<meta property="og:url" content="http://blaze-craft.com/matt/gag.php?id=<?php echo $id ? >" />
<meta property="og:image" content="http://blaze-craft.com/matt/get.php?id=<?php echo $id ?>" />
但它总是将值输出为0,即使它不是0。当我在页面上的其他地方回显它时,它也能工作吗?
任何帮助都将不胜感激!:D
好的,iv刚刚在源代码中看到它正在设置
<html>
<head>
<title>YourGag - Gag</title>
<meta property="og:title" content="MyGag - Gag" />
<meta property="og:type" content="activity" />
<meta property="og:url" content="http://blaze-craft.com/matt/gag.php?id=2" />
<meta property="og:image" content="http://blaze-craft.com/matt/get.php?id=2" />
<meta property="og:site_name" content="YourGag" />
<meta property="fb:admins" content="1254694731" />
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
但是当我使用facebook调试器时,它说那里有一个0而不是2!
seriosly wierd!
在尝试转换为int
之前,您是否尝试过调试$_GET['id']
的值?
根据文件(intval
):
返回值
成功时
var
的整数值,失败时0
的整数值。空数组返回0
,非空数组返回1
。
因此$_GET['id']
要么是空数组,要么不能作为整数值返回。
两件事:
- 你有没有试着看看是否设置了
$_GET['id']
变量 - 您应该转义元标记中发送的ID。例如
echo urlencode($id);
- 如果失败,制作一个非常简单的页面,如下所示:
if (isset($_GET['id'])) {
echo "id is set: '".$_GET['id']."'";
}
else {
echo "id is not set";
}
只是想看看发生了什么。
在使用intval()强制转换$id之前,它的值是多少?intval的返回值0告诉您$id不是要传递给函数的有效标量值。导致它失败的可能是对象、数组或其他值。
作为一种替代方案,您可以尝试:
$id = (int)$id;