FloorScan Posted May 26, 2012 Share Posted May 26, 2012 Hi there, I have the following problem, when I put in the onClick code (from analytics) i get a error Unexpected T_string. I have searched the internet but cannot get this solved. What is wrong with the syntax? $link = array('<a href="http://example.com" onClick="recordOutboundLink(this, 'Outbound Links', 'example.com');return false;">click here</a>','<a href="http://example.com/page/" onClick="recordOutboundLink(this, 'Outbound Links', 'example.com/page/');return false;">click here</a>'); Quote Link to comment https://forums.phpfreaks.com/topic/263152-onclick-javascript-in-php-string-not-working/ Share on other sites More sharing options...
Drummin Posted May 26, 2012 Share Posted May 26, 2012 $link = array("<a href=\"http://example.com\" onClick=\"recordOutboundLink(this, 'Outbound Links', 'example.com');return false;\">click here</a>","<a href=\"http://example.com/page/\" onClick=\"recordOutboundLink(this, 'Outbound Links', 'example.com/page/');return false;\">click here</a>"); Quote Link to comment https://forums.phpfreaks.com/topic/263152-onclick-javascript-in-php-string-not-working/#findComment-1348720 Share on other sites More sharing options...
.josh Posted May 26, 2012 Share Posted May 26, 2012 to be clear, the problem is your quotes aren't lined up right. You start off with single quote, so if you have single quote as part of the value you need to escape it (prefix with a backslash) so that php knows you want to use a literal quote as part of the value instead of closing the string. Quote Link to comment https://forums.phpfreaks.com/topic/263152-onclick-javascript-in-php-string-not-working/#findComment-1348790 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.