Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“如何转换LDAP”;“当加热时”;将时间戳20150527135501.0Z属性设置为PHP中的时间戳?_Php_Ldap_Timestamp - Fatal编程技术网

“如何转换LDAP”;“当加热时”;将时间戳20150527135501.0Z属性设置为PHP中的时间戳?

“如何转换LDAP”;“当加热时”;将时间戳20150527135501.0Z属性设置为PHP中的时间戳?,php,ldap,timestamp,Php,Ldap,Timestamp,如何在PHP中将LDAP“whenCreated”属性timestamp 20150527135501.0Z转换为timestamp $justthese = array("displayname","department" , "title","samaccountname", "mail", "whenCreated"); $result = ldap_search($ldap,$dn , $filter ,$justthese) or die ("Search failed"); $

如何在PHP中将LDAP“whenCreated”属性timestamp 20150527135501.0Z转换为timestamp

$justthese = array("displayname","department" , "title","samaccountname", "mail", "whenCreated"); 

$result = ldap_search($ldap,$dn , $filter ,$justthese) or die ("Search failed");
 $info = ldap_get_entries($ldap, $result);
print_r ($info);
for ($i=0; $i < $info["count"]; $i++) { 
echo "Name: ".$info[$i]["displayname"][0]."<br>\n"; 
echo "Department: ".$info[$i]["department"][0]."<br>\n"; 
echo "Created: ".$info[$i]["whenCreated"][0]."<br>\n"; 
}
$justthis=array(“显示名称”、“部门”、“标题”、“samaccountname”、“邮件”、“创建时”);
$result=ldap_search($ldap,$dn,$filter,$justthis)或die(“搜索失败”);
$info=ldap\u get\u条目($ldap,$result);
打印(信息);
对于($i=0;$i<$info[“count”];$i++){
echo“Name:”.$info[$i][“displayname”][0]。“
\n”; 回显“部门:”.$info[$i][“部门”][0]。“
\n”; echo“创建:”.$info[$i][“创建时”][0]。“
\n”; }
我得到了用户和部门的显示名称,但我没有得到创建的时间戳。在我的打印中($info)


我将时间戳设置为
20150527135501.0Z
。如何在PHP中打印此时间戳?

该问题可能与LDAP返回的属性有关。相反,请尝试:

echo "Created: ".$info[$i]["whencreated"][0]."<br>\n";

最好将上述内容转换为函数。

只是想澄清一下,当您尝试回显属性时,是属性为空的问题,还是希望时间戳采用人类可读的格式(或unix时间戳等其他格式)的问题?实际上,在我尝试进行打印时,两者都存在;然后我可以看到是否以.OZ格式创建了日期,但它没有以{echo“Created:”.$info[$i][“whencreated”][0]打印。“
\n”;我的想法可能是时间戳。任何帮助都将被感谢。第一行本身就起作用了。谢谢你,查德。感谢它,我的朋友。没问题@Dev!很高兴这解决了问题。别忘了点击左边的复选标记,接受它作为答案(:
    preg_match("/^(\d+).?0?(([+-]\d\d)(\d\d)|Z)$/i", $info[$i]["whencreated"][0], $matches);
    if (!isset($matches[1]) || !isset($matches[2])) {
        throw new \Exception(sprintf('Invalid timestamp encountered: %s', $info[$i]["whencreated"][0]));
    }
    $tz = (strtoupper($matches[2]) == 'Z') ? 'UTC' : $matches[3].':'.$matches[4];
    $date = new \DateTime($matches[1], new \DateTimeZone($tz));

    // Now print it in any format you like
    echo $date->format('Y-m-d H:i:s');