-3
echo '<a href="'. $site_url .'" onclick=" window.open('. $refferal_url .'); ">';

results

<a href="http://example.com/" onclick=" window.open(http://example.com/some-url/); ">

The problem is i can't get to put single quote before and after http://example.com/some-url/

because i always get the error.

How can i do this?

m3tsys
  • 3,859
  • 6
  • 27
  • 43
  • Instead of manually fiddling in / escaping quotes, appending the value per [`json_encode`](http://php.net/json_encode) / [`htmlspecialchars`](http://php.net/htmlspecialchars) would be most correct. – mario Oct 20 '15 at 23:29

1 Answers1

1

You have to escape the single quotes because they are in a single-quoted string. Add \' where you want the single quotes.

Example:

echo '<a href="'. $site_url .'" onclick=" window.open(\''. $refferal_url .'\'); ">';

By the way, "referral" has two rs, not two fs.

elixenide
  • 43,445
  • 14
  • 72
  • 97