-3

请修复这段代码。这就是它所说的“解析错误:语法错误,第 49 行 /home/timmycpc/public_html/ItemDatabase/index.php 中的意外 T_STRING”这是第 12 - 49 行:

<?php
$arr = json_decode(file_get_contents("url.com/file.json"),true);
$page = isset($_GET['p']) ? intval($_GET['p']) : 0;
$elementsPerPage = 20;
$elements = array_slice($arr, $page * $elementsPerPage, $elementsPerPage);
$totalpages = intval(count($arr)/$elementsPerPage);
if($_GET['p'] == ""){$_GET['p'] = '0';}
$whatpage = $_GET['p'];
if($whatpage > $totalpages){echo("<tr><td>Sorry this page does not exist. Please return to <a href='?p=0'>page 1</a>.</td></tr>"); exit;}
$link1 = $whatpage-1;
$link2 = $whatpage+1;
if($_GET['p'] == 0){$backbutton = "";} else {$backbutton = "<a href=?p=" . $link1 . ">Previous Page</a>";}
if($_GET['p'] == $totalpages){$nextbutton = "";} else {$nextbutton = "<a href=?p=" . $link2 . ">Next Page</a>";}
if($_GET['p'] == $totalpages or $_GET['p'] == 0){$middle = "";} else {$middle = " | ";}
$pagenav = $backbutton . $middle . $nextbutton;
echo('<tr><td colspan="5" align="center">'.$pagenav.'</td></tr>');
foreach($elements as $item)
{

$label = $item['label'];
$cost = $item['cost'];
$id = $item['paper_item_id'];
$member = $item['is_member'];
$patched = $item['is_bait'];

if ($member == "1") {
$member = "Yes";
}else{
$member = "No";
}

if ($patched == "1") {
$patched = "Yes";
}else{
$patched = "No";
}

$str .= "<tr><td><embed src="http://www.url.com/SWFViewer/items.swf?id=<?php echo($id); ?>"></td><td style='text-align: left !important;'><b>Name:</b> $label</td><td><b>Item ID:</b> $id</td><td><b>Members:</b> $member</td><td><b>Cost:</b> $cost coins</td><td><b>Patched:</b> $patched</td></tr>";
}

echo substr($str, 0, -5);
?></table></center></body></html>
4

2 回答 2

1

您的线路$str ...正在进出PHP String。这导致了解析错误。您必须转义\"引号、连接字符串或使用 HEREDoc。

有关详细信息,请参阅PHP 字符串手册

选项1:(最佳)您可以转义字符串中的双引号:(并删除<?php echo

$str .= "<tr><td><embed src=\"http://www.url.com/SWFViewer/items.swf?id=$id\"></td><td style='text-align: left !important;'><b>Name:</b> $label</td><td><b>Item ID:</b> $id</td><td><b>Members:</b> $member</td><td><b>Cost:</b> $cost coins</td><td><b>Patched:</b> $patched</td></tr>";

选项 2:连接您的字符串并使用单引号:

$str .= '<tr><td><embed src="http://www.url.com/SWFViewer/items.swf?id=' . $id . '"></td><td style="text-align: left !important;"><b>Name:</b> ' . $label . '</td><td><b>Item ID:</b> ' . $id . '</td><td><b>Members:</b> ' . $member . '</td><td><b>Cost:</b> ' . $cost . ' coins</td><td><b>Patched:</b> ' . $patched . '</td></tr>';

选项 3:(最慢)使用 HereDoc:

$str .= <<<EOF
<tr><td><embed src="http://www.url.com/SWFViewer/items.swf?id=$id"></td><td style="text-align: left !important;"><b>Name:</b> $label</td><td><b>Item ID:</b> $id</td><td><b>Members:</b> $member</td><td><b>Cost:</b> $cost coins</td><td><b>Patched:</b> $patched</td></tr>
EOF;
于 2012-10-25T00:54:39.123 回答
-1

尝试这个

$str .= "<tr><td><embed src=\"http://www.timmycp.co.cc/SWFViewer/items.swf?id=".$id."\"></td><td style='text-align: left !important;'><b>Name:</b> $label</td><td><b>Item ID:</b> $id</td><td><b>Members:</b> $member</td><td><b>Cost:</b> $cost coins</td><td><b>Patched:</b> $patched</td></tr>";

于 2012-10-25T00:48:27.890 回答