Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

$htmlvariable = "<a onclick="calledfunction('string',javascriptvariable);">Calling</a>";
share|improve this question
    
And what is the problem? –  Felix Kling Aug 22 '14 at 13:29

2 Answers 2

up vote 2 down vote accepted

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

share|improve this answer

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

$htmlvariable = "<a onclick=\"calledfunction('string',javascriptvariable);\">Calling</a>";
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.