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 to comment
Share on other sites

$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 to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.