2009-06-02 65 views
0

我想爲什麼我收到此錯誤弄清楚PHP語法錯誤

"Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/idgcca/public_html/web-design-samples-testing.php on line 64"


echo ' 
<div style="float:left; width: 180px; margin: 20px 0px 10px 0px;"><a rel="lightbox[web]" title="'. $post->title .'" onmousedown="this.title='<a target=\'_blank/\' href=\'http:www.google.ca/\'>Google</a>';" onmouseout="this.title='';" href="'. $post->url . '"> 

<img src="' . $post->thumb . '" border="0"/></a> <div class="design-sample-txt">'. $post->author.'</div></div> 

'; 

IM一個PHP福利局只是想了解它在我自己的,但我的頭轉向。一個幫助將非常讚賞...

回答

4

這裏是你的問題:

this.title='< 

你應該逃離這個報價。以及關閉a標籤。像這樣:

echo '<div style="float:left; width: 180px; margin: 20px 0px 10px 0px;"> 
    <a rel="lightbox[web]" title="'. $post->title .'" 
     onmousedown="this.title=\'<a target=\'_blank/\' href=\'http:www.google.ca/\'>Google</a>\';" 
     onmouseout="this.title=\'\';" href="'. $post->url . '">  
    <img src="' . $post->thumb . '" border="0"/></a> 
    <div class="design-sample-txt">'. $post->author.'</div> 
</div>'; 
+0

確定..林混淆...你能複製並粘貼確切的代碼,請我嘗試看看,但everythign關閉... – 2009-06-02 13:34:03

+0

...(15個字符) – 2009-06-02 13:36:42

1

該行上有一個未終止的字符串。你應該用這樣的斜線來避開你的報價「

echo」< div style = ** \「** float:left; .....」;

1

您需要在單引號字符串中轉義單引號。

echo '<div style="float:left; width: 180px; margin: 20px 0px 10px 0px;"><a rel="lightbox[web]" title="'. $post->title .'" onmousedown="this.title=\'<a target=\'_blank/\' href=\'http:www.google.ca/\'>Google</a>\';" onmouseout="this.title=\'\';" href="'. $post->url . '">'; 
0

我建議你將代碼分成多行以便閱讀。

這將有助於調試這種線。

看看在echo operator例子

要回答你的問題,也有在你的代碼濫用一些報價。你需要逃避它們。

echo '<div style="float:left; width: 180px; margin: 20px 0px 10px 0px;"> 
<a rel="lightbox[web]" title="'. $post->title .'" onmousedown="this.title=\'<a 
target=\'_blank/\' href=\'http:www.google.ca/\'>Google</a>\';" 
onmouseout="this.title=\'\';" href="'. $post->url . '"><img src="' . $post->thumb . '" 
border="0"/></a> <div class="design-sample-txt">'. $post->author.'</div></div>'; 
0

假設你到底粘貼代碼中,第一錯誤是正確的開始,什麼時候結束第一次報價。它期望閱讀:

echo ' title .'; 

兩個相鄰的引號沒有任何意義。

0

你從SilentGhost得到了你的答案。

我會使用HEREDOC這樣的事情。

0

你應該對這些屬性值使用htmlspecialchars

function html($str, $charset=null) { 
    if (!is_null($charset)) { 
     return htmlspecialchars($str, ENT_QUOTES, $charset); 
    } else { 
     return htmlspecialchars($str, ENT_QUOTES); 
    } 
} 

echo ' 
    <div style="float:left; width: 180px; margin: 20px 0px 10px 0px;"> 
     <a rel="lightbox[web]" 
      title="' . html($post->title) . '" 
      onmousedown="' . html('this.title=\'<a target="_blank" href="http://www.google.ca/">Google</a>\'') . '" 
      onmouseout="' . html('this.title=""') . '" 
      href="' . html($post->url) . '"> 
      <img src="' . html($post->thumb) . '" border="0"/></a> 
     <div class="design-sample-txt">' . html($post->author) . '</div> 
    </div> 
';