Parse error: syntax error, unexpected T_STRING 59 [closed]

匿名 (未验证) 提交于 2019-12-03 02:43:01

问题:

Please fix this piece of coding. This is what it says "Parse error: syntax error, unexpected T_STRING in /home/timmycpc/public_html/ItemDatabase/index.php on line 49"This is line 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> 

回答1:

Your line $str ... is breaking in and out of a PHP String. Which is causing the parse error. You have to either escape \" quotes, concatenate your strings, or use a HEREDoc.

See the PHP Manual on Strings for more information.

Option 1: (Best) You can escape the double quotes within your string: (And remove the <?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>"; 

Option 2: Concatenate your string and use single quotes:

$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>'; 

Option 3: (Slowest) Use a 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; 


回答2:

try this

$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>";



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!