Page 1 of 1

Parse err: syntax err, unexpected T_CONSTANT_ENCAPSED_STRING

Posted: Fri May 01, 2009 3:59 am
by GJM
I am very new to php coding. Your patients is appreciated.

Here is the error that I am getting:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/tp/public_html/sites/all/modules/custom/tp/tp.module on line 1905
I have a link that works perfectly when written like this:

Code: Select all

 
$output .= '<div id="iu"><a href="http://click.lksr.com/fs-bin/click?id=wup&offerid=15&subid=0&type=4"><img src="http://ad.lksr.com/fs-bin/show?id=wup&bids=15&subid=0&type=4&gridnum=5" alt="Free Samples"/></a></div>';
 
But if I try to have it open in a popover window by adding this to the link:

Code: Select all

 
onclick="window.open(this.href,'','resizable=yes,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,fullscreen=no,dependent=no,width=815,height=824,status'); return false"
 
Here is how I have inserted it:

Code: Select all

 
$output .= '<div id="iu"><a onclick="window.open(this.href,'','resizable=yes,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,fullscreen=no,dependent=no,width=815,height=824,status'); return false" href="http://click.lksr.com/fs-bin/click?id=wup&offerid=15&subid=0&type=4"><img src="http://ad.lksr.com/fs-bin/show?id=wup&bids=15&subid=0&type=4&gridnum=5" alt="Free Samples"/></a></div>';
 
I find that I get the error I mentioned above.

I have looked around and I have seen it suggested that instead of

Code: Select all

 
onclick="window.open ..........
 
 
I should write

Code: Select all

 
onclick=\"window.open ......... 
 
 
put a "\" where ever there is a double quote. I have tried that and it doesn't seem to work.

Could someone please give a little guidance as to why the extra bit of code is giving me that error?

Thanks again in advance.

Re: Parse err: syntax err, unexpected T_CONSTANT_ENCAPSED_STRING

Posted: Fri May 01, 2009 4:21 am
by requinix
The answer is right there in your post.

Code: Select all

$output .= '<div id="iu"><a onclick="window.open(this.href,'','resizable=yes,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,fullscreen=no,dependent=no,width=815,height=824,status'); return false" href="http://click.lksr.com/fs-bin/click?id=wup&offerid=15&subid=0&type=4"><img src="http://ad.lksr.com/fs-bin/show?id=wup&bids=15&subid=0&type=4&gridnum=5" alt="Free Samples"/></a></div>';
See how a lot of the string is red? See how a part of it suddenly turns black? That's not a good thing. Maybe it's because PHP doesn't think it's a string anymore...

The point of turning " into \" is to tell PHP that the " doesn't mark the end of the string. So it's just a regular character. It's the backslash that's magical.
Now take that idea and apply it to your code. The string starts and ends with a ' so when PHP finds a ' inside it thinks the string is over. But that's not what you want.

Re: Parse err: syntax err, unexpected T_CONSTANT_ENCAPSED_STRING

Posted: Fri May 01, 2009 4:25 am
by Benjamin
It's interesting how these syntax errors are suddenly visible with syntax highlighting ;)

Re: Parse err: syntax err, unexpected T_CONSTANT_ENCAPSED_STRING

Posted: Fri May 01, 2009 11:39 am
by GJM
I feel kinda dumb asking this, but, how did you turn on syntax highlighting?
It's interesting how these syntax errors are suddenly visible with syntax highlighting
The second question I have is with regard to the solution......where the code changes color is in between two single quotes ( ' ). If I am reading the response correctly, I should be inserting a backslash just before both of those single quotes. Is that correct?

Could you confirm for me that the code should look like this:

Code: Select all

 
$output .= '<div id="iu"><a onclick="window.open(this.href,'',\'resizable=yes,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,fullscreen=no,dependent=no,width=815,height=824,status\'); return false" href="http://click.lksr.com/fs-bin/click?id=wup&offerid=15&subid=0&type=4"><img src="http://ad.lksr.com/fs-bin/show?id=wup&bids=15&subid=0&type=4&gridnum=5" alt="Free Samples"/></a></div>';
 
that is the backslach should go here:
(this.href,'',\'resizable=yes,........height=824,status\')

Again, Thanks for your Assistance!

Re: Parse err: syntax err, unexpected T_CONSTANT_ENCAPSED_STRING

Posted: Fri May 01, 2009 12:13 pm
by GJM
hmmmm, I think I missed something. I quickly tried it and my interpretation of the solution didn't work.

Sorry for the bother, but I am not sure what it is I am missing.

Again, thanks for the help :?

Re: Parse err: syntax err, unexpected T_CONSTANT_ENCAPSED_STRING

Posted: Fri May 01, 2009 1:37 pm
by GJM
..... that is weird, I am not sure why the backslashes didn't showup in the Fri May 01, 2009 10:39 am post, but now only the ( ' ) are a different color . . . . . . . I did put them in when I posted it, I am sure of it. I'm not sure what to say.

Wish I could be more help. :?

Re: Parse err: syntax err, unexpected T_CONSTANT_ENCAPSED_STRING

Posted: Fri May 01, 2009 1:43 pm
by requinix
- For highlighting, use or just the shorthand .
*cough* hey astion, stick some message or something into the posts so people notice

- Yes, you're right, use a backslash in front of the apostrophe. But there are two more in there you missed.

- Occasionally the forum software will tweak code: the highlighting works but characters disappear. I've seen it happen with quotes and semicolons.

Re: Parse err: syntax err, unexpected T_CONSTANT_ENCAPSED_STRING

Posted: Fri May 01, 2009 1:47 pm
by jam57
tasairis is right, look where you have:

'',\'

you should have:

\'\',\'

Re: Parse err: syntax err, unexpected T_CONSTANT_ENCAPSED_STRING

Posted: Fri May 01, 2009 2:27 pm
by GJM
That's awesome folks! It is working perfectly.
- Yes, you're right, use a backslash in front of the apostrophe. But there are two more in there you missed.
I didn't think that those other 2 needed to have the backslash on them because the code hadn't changed color ... stupid me.

Again, thank you very much for the help!