解析错误:语法错误,意外T_STRING
问题描述:
我一直得到这个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>';
}
}
}
?>
答
你必须小心你的单引号和双引号。在该行上,您有
'<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>';
通过各前添加\”,你逃避它,这样它被认为是您的字符串的一部分。
答
你要逃避的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>';
答
你需要逃跑报价: '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>';
答
打印“> imageList->图像[0 ] - > sourceURL。'“width =”100“>';
应该是
打印'offerURL属性。 “> imageList->图像[0] - > sourceURL'。” 宽度= “100”>';
假设_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>';
您使用单引号('
)来界定你的字符串,但该字符串还包含单引号(例如,'_trackPageview'
。您需要转义这些(\'
),否则PHP会将它们表示为字符串的结尾,并且会给出您遇到的意外令牌错误。
谢谢工作完美 – 2011-06-16 22:04:46