2013-07-12 48 views
-2

我有以下的PHP代碼。當我運行它,我得到的錯誤。「*解析錯誤:語法錯誤,在/home/ashb/public_html/databaseconnect.php意外T_STRING上線20」 *代碼中出現意外的T-STRING?

當我有代碼的工作,第20行是:$xml_output .= "<?xml-stylesheet href=\"$xslt_file\" type=\"text/xsl\" ?>";

我需要將我的代碼更改爲$xml_output .= "<?xml-stylesheet href=\"$xslt_file\" type=\"text/css\" ?>";。它在改變之後發生了錯誤。

它有什麼問題?完整的代碼已包含在下面。

注意: $ xslt_file變量已針對上述不同代碼行進行了相應更改。

<?php 

header("Content-type: text/xml"); 

$host = "###"; 
$user = "###"; 
$pass = "###"; 
$database = "###"; 
$xslt_file = "/xmlstyle.css"; 
$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host."); 
mysql_select_db($database, $linkID) or die("Could not find database."); 

$query = "SELECT * FROM users WHERE Username = 'Username4';"; 


$resultID = mysql_query($query, $linkID) or die("Data not found."); 

$xml_output = "<?xml version=\"1.0\"?>\n"; 
//$xml_output .= "<?xml-stylesheet href=\"$xslt_file\" type=\"text/xsl\" ?>"; 
$xml_output .= "<?xml-stylesheet href=\"$xslt_file\" type=\"text/css\" ?>"; 

$xml_output .= "<Users>\n"; 

for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){ 
    $row = mysql_fetch_assoc($resultID); 
    $xml_output .= "\t<Person>\n"; 
    $xml_output .= "\t\t<Username>" . $row['username'] . "</Username>\n"; 
    $xml_output .= "\t\t<Firstname>" . $row['firstname'] . "</Firstname>\n"; 
    $xml_output .= "\t\t<Lastname>" . $row['lastname'] . "</Lastname>\n"; 
    $xml_output .= "\t\t<Title>" . $row['Title'] . "</Title>\n"; 
    $xml_output .= "\t\t<Description>" . $row['Description'] . "</Description>\n"; 
    $xml_output .= "\t\t<Location>" . $row['Location'] . "</Location>\n"; 
    $xml_output .= "\t\t<Feeling>" . $row['Feeling'] . "</Feeling>\n"; 
     // Escaping illegal characters 
     $row['text'] = str_replace("&", "&", $row['text']); 
     $row['text'] = str_replace("<", "<", $row['text']); 
     $row['text'] = str_replace(">", "&gt;", $row['text']); 
     $row['text'] = str_replace("\"", "&quot;", $row['text']); 

    $xml_output .= "\t</Person>\n"; 
} 

$xml_output .= "</Users>"; 

echo $xml_output; 

?> 

回答

1

上面的行解析拋出錯誤的行去香蕉。

//$xml_output .= "<?xml-stylesheet href=\"$xslt_file\" type=\"text/xsl\" ?>"; 

註釋不註釋掉最後>「;?。

使用像phpstorm /的NetBeans/Zend公司的/ etc的IDE顯示了這個馬上

+0

完美謝謝:-) – googleyberry