Hey there! any question in your mind? Ask It Now!.

Popular Categories





Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_STRING

+1 vote
248 views
asked in Programming by jack (1,440 points)
Hi all, I am trying to simply call a onClick function on a button and facing this error:

 

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_STRING in /home/test/html/home.php on line 121

 

My button html code is:

<button onclick="_gaq.push(['_trackEvent', 'category', 'action', 'opt_label', 1]);"></button>

In this line this error is coming.

I don&rsquo;t know what is happening I am calling _gaq.push on onclick event and this unexpected error is coming, Please give me solution for the same.
commented by Rens Pontier
It should specify a line number as well. Probably the error lies 1 line earlier. To determine the actual problem, I would need to see the code fragment. It's virtually impossible for me to determine the problem without seeing it.
Possible errors: a forgotten comma (,), quote(') or semi-colon (;)

1 Answer

+1 vote
answered by payel (1,640 points)
selected by jack
 
Best answer

Hi Jack, this error comes usually when we add apostrophe in between of PHP code, whenever are using any other code like html or java script in PHP I recommend to use slash before the apostrophe.  If we talk about your code I think you are using this button in PHP or printing this button dynamically.

See your code:

<button onclick="_gaq.push(['_trackEvent', 'category', 'action', 'opt_label', 1]);"></button>

You have to just add like:

<button onclick="_gaq.push([\'_trackEvent\',\ 'category\',\ 'action\', \'opt_label\', 1]);"></button>

 

Here slash (\) is saying to code please avoid apostrophe and code compile this line normally.

Try this it would help you.

commented by jack (1,440 points)
Thanks Dear @Payel its really helped me.
commented by anonymous
There is another option, if you really do not want to see backslashes everywhere , you can use heredoc (and nowdoc) syntax, as per PHP.net:

https://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

Related Questions

+2 votes
1 answer 191 views
+1 vote
1 answer 160 views
asked in Programming by amit_pammu Expert (5,030 points)
+1 vote
1 answer 796 views
0 votes
1 answer 171 views
+1 vote
1 answer 205 views
+3 votes
1 answer 3,629 views
+4 votes
5 answers 3,139 views
0 votes
2 answers 305 views
+1 vote
1 answer 175 views

Not a Member yet?

Ask to Folks Login

My Account
452 Folks are online
1 members and 451 guest online
Your feedback is highly appreciated