请修好这段编码。这就是它所说的“解析错误:语法错误,第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>
答案 0 :(得分:1)
您的第$str ...
行正在进出PHP String。这导致了解析错误。您必须转义\"
引号,连接字符串或使用HEREDoc。
有关详细信息,请参阅PHP Manual on Strings。
选项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;
答案 1 :(得分:-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>";