0

I have a Problem with using a HTML into PHP variable. Please see the example below ??

$htmlvariable = "<a onclick="calledfunction('string',javascriptvariable);">Calling</a>";
1
  • And what is the problem? Commented Aug 22, 2014 at 13:29

2 Answers 2

2

Use single quotes and escape single quotes inside the string with a \ :

$htmlvariable = '<a onclick="calledfunction(\'string\',javascriptvariable);">Calling</a>';

Otherwise, this will produce this error :

Parse error: syntax error, unexpected T_STRING

Sign up to request clarification or add additional context in comments.

Comments

0

To include those " in a PHP double-quoted string, you'll need to escape them:

$htmlvariable = "<a onclick=\"calledfunction('string',javascriptvariable);\">Calling</a>";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.