Search code examples
phperror-handlingsingle-quotes

syntax error, unexpected T_STRING, expecting ',' or ';'”


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?


Solution

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