-2

我有以下 PHP 代码。当我运行它时,我收到错误' *Parse error: syntax error, unexpected T_STRING in /home/ashb/public_html/databaseconnect.php on line 20'.*

当我让代码工作时,第 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; 

?> 
4

1 回答 1

1

对抛出错误的行上方的行的解析是香蕉。

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

评论没有评论最后的 ?>";

使用像 phpstorm/netbeans/zend/etc 这样的 IDE 会立即显示这一点。

于 2013-07-12T14:06:35.167 回答