解析错误:语法错误,意外T_STRING

时间:2011-06-16 21:44:52

标签: php api

我一直得到这个T_STRING Parse错误我不知道它是什么,但它在第34行向底部,任何帮助表示赞赏。

<form action="product_search">
<input type="text" name="search" value="<? echo htmlentities($_GET['search']); ?>"/>
<input type="submit" value="Search"/>
</form>
<?
$search_items = urlencode($_GET['search']);
// $search_items = 'eee';
$items = simplexml_load_file('http://api.shopping.com/dsp/linkin_id-8005272/keyword-'.$search_items);

if (($items) && (strlen($search_items) > 1)) {
print "<pre>\n";
foreach ($items->result->domain->{domain-listing} as $item) {
print l($item->title, $item->url)."<br/>";
}
print '</pre>';
}
else {
?>
Search for products-- computers, eee pcs, sub-notebooks, and all that great stuff!
<?
}
?>

<?
$tids = explode(',',arg(2));
foreach ($tids as $tid) {
$term_info = taxonomy_get_term($tid);
$search_items = urlencode($term_info->name);
$items = simplexml_load_file('http://publisher.api.shopping.com/publisher/3.0/rest/GeneralSearch?identity.apiKey=[API KEY]&tr.trackingId=[LINKIN ID]&nf.keyword='.$search_items);

if (($items) && (strlen($search_items) > 1)) {
foreach ($items->categories->category->items->offer as $item) {
print '<div style="float: left; width: 120px; padding: 10px; overflow: auto; display: block;">';
//right here is the error
print '<a rel="nofollow" onclick="javascript:_gaq.push(['_trackPageview', '/outgoing/article_exit_link/789591']);" href="'.$item->offerURL.'"><img src="'.$item->imageList->image[0]->sourceURL.'" width="100"></a>';
print "<br/>".l($item->name, $item->offerURL, array(), NULL, NULL, TRUE);
print '</div>';
}
}
}
?>

5 个答案:

答案 0 :(得分:1)

你必须小心你的单引号和双引号。在那一行,你有

'<a rel="nofollow" onclick="javascript:_gaq.push(['

打开和关闭你的字符串。然后_trackPageview会导致错误,因为它不是字符串的一部分。

你可以尝试下面的(未经测试的):

print '<a rel="nofollow" onclick="javascript:_gaq.push([\'_trackPageview\', \'/outgoing/article_exit_link/789591\']);" href="\'.$item->offerURL.\'"><img src="\'.$item->imageList->image[0]->sourceURL.\'" width="100"></a>';

通过在每个'之前添加\,您将其转义,以便将其视为字符串的一部分。

答案 1 :(得分:0)

你必须转义onclick-code中的单引号:

print '<a rel="nofollow" onclick="javascript:_gaq.push([\'_trackPageview\', \'/outgoing/article_exit_link/789591\']);" href="'.$item->offerURL.'"><img src="'.$item->imageList->image[0]->sourceURL.'" width="100"></a>';

答案 2 :(得分:0)

您需要转义引号:

print '<a rel="nofollow" onclick="javascript:_gaq.push([\'_trackPageview\', \'/outgoing/article_exit_link/789591\']);" href="'.$item->offerURL.'"><img src="'.$item->imageList->image[0]->sourceURL.'" width="100"></a>';

答案 3 :(得分:0)

打印'offerURL。'“&gt; imageList-&gt; image [0] - &gt; sourceURL。'”width =“100”&gt;';

应该是

打印'offerURL。'“&gt; imageList-&gt; image [0] - &gt; sourceURL。'”width =“100”&gt;';

假设_trackPageView是一个变量。否则,转义单引号:\'

答案 4 :(得分:0)

我认为您收到错误的行是:

print '<a rel="nofollow" onclick="javascript:_gaq.push(['_trackPageview', '/outgoing/article_exit_link/789591']);" href="'.$item->offerURL.'"><img src="'.$item->imageList->image[0]->sourceURL.'" width="100"></a>';

您使用单引号(')来分隔字符串,但字符串也包含单引号(例如,'_trackPageview'。您需要转义这些(\') ,因为否则PHP会将它们视为字符串的结尾,并为您提供您遇到的意外令牌错误。

相关问题