Jump to content

onClick javascript in PHP string not working


FloorScan

Recommended Posts

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>');

 

 

$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>");

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.