我正在做的是通过循环数据来创建一个JavaScript数组,其中包含PHP变量之外的对象。运行代码时出现错误:
SyntaxError:缺少}属性列表后[Meer info] getdata.php:1:35650注意:{在第1行第35613列中打开
我尝试复制生成的javascript变量并通过控制台进行声明,但文本在对象中间变成灰色。我看不到变量声明有任何问题。
错误消息:
SyntaxError: missing } after property list[Meer info] getdata.php:1:35650note: { opened at line 1, column 35613
PHP循环
if (TRUE === ldap_bind($ldap_connection, $ldap_username, $ldap_password)){
//Your domains DN to query
$ldap_base_dn = '**********';
//Get standard users and contacts
$search_filter = '(|(objectCategory=person)(objectCategory=contact))';
//Connect to LDAP
$result = ldap_search($ldap_connection, $ldap_base_dn, $search_filter);
if (FALSE !== $result){
$entries = ldap_get_entries($ldap_connection, $result);
echo "<script>var users = [";
for ($x=0; $x<$entries['count']; $x++){
//Windows Usernaame
$LDAP_samaccountname = "";
if (!empty($entries[$x]['samaccountname'][0])) {
$LDAP_samaccountname = $entries[$x]['samaccountname'][0];
if ($LDAP_samaccountname == "NULL"){
$LDAP_samaccountname= "";
}
} else {
//#There is no samaccountname s0 assume this is an AD contact record so generate a unique username
$LDAP_uSNCreated = $entries[$x]['usncreated'][0];
$LDAP_samaccountname= "CONTACT_" . $LDAP_uSNCreated;
}
//Last Name
$LDAP_LastName = "";
if (!empty($entries[$x]['sn'][0])) {
$LDAP_LastName = $entries[$x]['sn'][0];
if ($LDAP_LastName == "NULL"){
$LDAP_LastName = "";
}
}
//First Name
$LDAP_FirstName = "";
if (!empty($entries[$x]['givenname'][0])) {
$LDAP_FirstName = $entries[$x]['givenname'][0];
if ($LDAP_FirstName == "NULL"){
$LDAP_FirstName = "";
}
}
//Company
$LDAP_CompanyName = "";
if (!empty($entries[$x]['company'][0])) {
$LDAP_CompanyName = $entries[$x]['company'][0];
if ($LDAP_CompanyName == "NULL"){
$LDAP_CompanyName = "";
}
}
//Department
$LDAP_Department = "";
if (!empty($entries[$x]['department'][0])) {
$LDAP_Department = $entries[$x]['department'][0];
if ($LDAP_Department == "NULL"){
$LDAP_Department = "";
}
}
//Job Title
$LDAP_JobTitle = "";
if (!empty($entries[$x]['title'][0])) {
$LDAP_JobTitle = $entries[$x]['title'][0];
if ($LDAP_JobTitle == "NULL"){
$LDAP_JobTitle = "";
}
}
//userPrincipalName
$LDAP_userMail = "";
if (!empty($entries[$x]['userPrincipalName'][0])) {
$LDAP_userMail = $entries[$x]['userPrincipalName'][0];
if ($LDAP_userMail == "NULL"){
$LDAP_userMail = "";
}
}
//FAX Number
$LDAP_OfficeFax = "";
if (!empty($entries[$x]['facsimiletelephonenumber'][0])) {
$LDAP_OfficeFax = $entries[$x]['facsimiletelephonenumber'][0];
if ($LDAP_OfficeFax == "NULL"){
$LDAP_OfficeFax = "";
}
}
//Mobile Number
$LDAP_CellPhone = "";
if (!empty($entries[$x]['mobile'][0])) {
$LDAP_CellPhone = $entries[$x]['mobile'][0];
if ($LDAP_CellPhone == "NULL"){
$LDAP_CellPhone = "";
}
}
//Telephone Number
$LDAP_DDI = "";
if (!empty($entries[$x]['telephonenumber'][0])) {
$LDAP_DDI = $entries[$x]['telephonenumber'][0];
if ($LDAP_DDI == "NULL"){
$LDAP_DDI = "";
}
}
//Email address
$LDAP_InternetAddress = "";
if (!empty($entries[$x]['mail'][0])) {
$LDAP_InternetAddress = $entries[$x]['mail'][0];
if ($LDAP_InternetAddress == "NULL"){
$LDAP_InternetAddress = "";
}
}
//Home phone
$LDAP_HomePhone = "";
if (!empty($entries[$x]['homephone'][0])) {
$LDAP_HomePhone = $entries[$x]['homephone'][0];
if ($LDAP_HomePhone == "NULL"){
$LDAP_HomePhone = "";
}
}
echo " {login: '".$LDAP_samaccountname ."', name: '". $LDAP_FirstName . $LDAP_LastName . "', mail: '". $LDAP_userMail . "', company: '" . $LDAP_CompanyName . "', department: '" . $LDAP_Department . "', title: '" . $LDAP_JobTitle ."'},";
} //END for loop
} //END FALSE !== $result
ldap_unbind($ldap_connection); // Clean up after ourselves.
echo("];</script>");
} //END ldap_bind
预期结果是所有用户将在数组中拥有自己的对象。
实际结果:可以创建一个包含对象的数组,但是在76个对象之后,它无法设置变量并给出上述错误消息