2011-06-16 161 views
-3

我一直得到這個T_STRING解析錯誤im不知道它是什麼,但它的行34底部,任何幫助表示讚賞。解析錯誤:語法錯誤,意外T_STRING

<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>'; 
} 
} 
} 
?> 

回答

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

通過各前添加\」,你逃避它,這樣它被認爲是您的字符串的一部分。

+0

謝謝工作完美 – 2011-06-16 22:04:46

0

你要逃避的onclick碼單引號:

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

你需要逃跑報價: 'offerURL屬性'

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

打印「> imageList->圖像[0 ] - > sourceURL。'「width =」100「>';

應該是

打印'offerURL屬性。 「> imageList->圖像[0] - > sourceURL'。」 寬度= 「100」>';

假設_trackPageView是一個變量。否則,逃單引號:\」

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會將它們表示爲字符串的結尾,並且會給出您遇到的意外令牌錯誤。

相關問題