Home > Back-end >  Syntax problem with converting html code to a php variable which also includes Javascript
Syntax problem with converting html code to a php variable which also includes Javascript

Time:11-01

I have this line of code which works well, but I want to convert into a PHP variable:

<a href="javascript:void(0);" onClick="javascript:freezModel('view_assumptions.php?id=<?php echo $adminArr['id'];?>&act=freez')" >

I have tried this:

$unlock='<a href="javascript:void(0);" onClick="javascript:freezModel("view_assumptions.php?id='.$adminArr["id"].'&act=freez")" ></a>';

I thought it was an escaping issue so I added the back slashes before the second ":

$unlock='<a href="javascript:void(0);" onClick="javascript:freezModel(\"view_assumptions.php?id='.$adminArr["id"].'&act=freez\")" ></a>';

But still no luck. Why does this not work???

CodePudding user response:

Your situation will be better handled using heredoc.

Try this instead:

<?php
$unlock = <<<EOS
<a href="javascript:void(0);" onClick="javascript:freezModel('view_assumptions.php?id={$adminArr['id']}&act=freez')" >
EOS;

CodePudding user response:

You must use ' instead of " for freezModel(), and scape it:

$unlock = '<a href="javascript:void(0);" onClick="javascript:freezModel(\'view_assumptions.php?id='.$adminArr["id"].'&act=freez\');" ></a>';

Using " you are closing your onclick property.

  •  Tags:  
  • php
  • Related