tags:

views:

97

answers:

7

I am trying to figure out why I'm getting this error

"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 a PHP newb just trying to understand it on my own but my head is turning. A help would be pretty much appreciated...

+3  A: 

here is your problem:

this.title='<

you should escape this quote. and the one at the closing a tag too. like this:

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>';
SilentGhost
ok.. Im confused... can you just copy and paste the exact code please Im trying to look at it but everythign is closed...
kwek-kwek
... (15 characters)
Boris Guéry
+1  A: 

You have an unterminated string on that line. You should escape your quotes with a slash like this \"

echo "<div style=\"float:left;.....";

Absolut40
+1  A: 

You need to escape single-quotes in a single-quote-string.

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 . '">';
Florian
A: 

I would advise you to split your code in multiple lines for readability.

It'll help to debug this kind of line.

Take a look at the echo operator examples

To answer to your question, there are some quotes misused in your code. You need to escape them.

    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>';
Boris Guéry
A: 

Assuming you pasted the code exactly, the first error is right at the beginning, when you end the first quote. It expects that to read:

echo ' title .';

The two quotes next to each other don't make any sense.

Marcus Downing
He's edited the code since I posted this.
Marcus Downing
A: 

You got your answer from SilentGhost.

I would use HEREDOC for such things.

Itay Moav
A: 

You should use htmlspecialchars on those attribute values:

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/"&gt;Google&lt;/a&gt;\'') . '"
           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>
';
Gumbo