我似乎无法找到我错过关闭声明的地方。
我一直收到此错误
PHP Parse error: syntax error, unexpected $end in /var/www/html/gs_phonebook.php on line 50
这是我的代码。
[php]
<?php
// File: gs_phonebook.php
// version: 1.0
// Description: Generating a XML Phonebook from FreePBX MySQL DB
//!!Enable for Debug only!!
error_reporting(E_ALL);
ini_set("display_errors",ON);
// Database settings
$DBhost="comms.****";
$DBuser="****";
$DBpass="****";
$DBdatabase="asterisk";
// Connect to the Database and get all devices
$DBlink=mysql_connect($DBhost,$DBuser,$DBpass) or die("Could not connect to host.");
mysql_select_db($DBdatabase,$DBlink) or die("Could not find database.");
$DBquery="SELECT user,description FROM devices ORDER BY descriptionASC";
$QUERYresult=mysql_query($DBquery,$DBlink) or die("Data not found.");
//Setup XMLWriter
$writer =newXMLWriter();
$writer->openURI('/tftpboot/gs_phonebook.xml');
$writer->setIndent(4);
//Beginn output
$writer->startDocument('1.0');
$writer->startElement('AddressBook');
//Add extensions / contacts from devices to the xml phonebook
while($contact=mysql_fetch_array($QUERYresult)){
$writer->startElement('Contact');
$writer->writeElement('LastName',$contact['description']);
$writer->writeElement('FirstName',");
$writer->startElement('Phone');
$writer->writeElement('phonenumber',$contact[user]);
$writer->writeElement('accountindex','0');
$writer->endElement();
$writer->endElement();
}
$writer->endElement();
$writer->endDocument();$writer->flush();
?>
[/php]
答案 0 :(得分:2)
$writer->writeElement('FirstName',");
这看起来像双引号而不是2个单引号。您可以通过SO代码块上的混乱颜色来判断。
应该是这样的:
$writer->writeElement('FirstName','');
答案 1 :(得分:0)
正如代码突出显示的那样,在这一行:
$writer->writeElement('FirstName',");
您的双引号不匹配 - 您需要''
代替"
(或代替"
)
答案 2 :(得分:0)
您尚未关闭此行的双引号
$writer->writeElement('FirstName',");
您可以改用
<?php
// File: gs_phonebook.php
// version: 1.0
// Description: Generating a XML Phonebook from FreePBX MySQL DB
//!!Enable for Debug only!!
error_reporting(E_ALL);
ini_set("display_errors",ON);
// Database settings
$DBhost="comms.****";
$DBuser="****";
$DBpass="****";
$DBdatabase="asterisk";
// Connect to the Database and get all devices
$DBlink=mysql_connect($DBhost,$DBuser,$DBpass) or die("Could not connect to host.");
mysql_select_db($DBdatabase,$DBlink) or die("Could not find database.");
$DBquery="SELECT user,description FROM devices ORDER BY descriptionASC";
$QUERYresult=mysql_query($DBquery,$DBlink) or die("Data not found.");
//Setup XMLWriter
$writer =newXMLWriter();
$writer->openURI('/tftpboot/gs_phonebook.xml');
$writer->setIndent(4);
//Beginn output
$writer->startDocument('1.0');
$writer->startElement('AddressBook');
//Add extensions / contacts from devices to the xml phonebook
while($contact=mysql_fetch_array($QUERYresult)){
$writer->startElement('Contact');
$writer->writeElement('LastName',$contact['description']);
$writer->writeElement('FirstName',"");
$writer->startElement('Phone');
$writer->writeElement('phonenumber',$contact[user]);
$writer->writeElement('accountindex','0');
$writer->endElement();
$writer->endElement();
}
$writer->endElement();
$writer->endDocument();$writer->flush();
?>
答案 3 :(得分:0)
此行中的错误
$writer->writeElement('FirstName',");
你可以给两个双引号
$writer->writeElement('FirstName',"");
或两个单引号
$writer->writeElement('FirstName','');
答案 4 :(得分:0)
您应该添加双引号来代替单引号。 如果您想添加单引号,请添加''。
$写入器的&GT; writeElement( “姓”, “”);
双引号不会产生任何错误。删除单引号并添加双引号。