0

i'm trying to show a result of var_export() in a separate div container.

$value = var_export($myarray,true);
echo "<script>$('#div_debug').html('$value');</script>";

and i get the this error:

SyntaxError: unterminated string literal

can anyone help me?

With ordinary Strings the Code is Working fine, but not with th eresult of of Var_dump/var_export

  • As the result of a var_export may contain quotes, you have to escape them before injecting it into your js – Mark Baker Aug 01 '16 at 11:36
  • 1
    echo ""; – Quynh Nguyen Aug 01 '16 at 11:37
  • This might help explain why you're getting that specific error: http://stackoverflow.com/questions/508269/how-do-i-break-a-string-across-more-than-one-line-of-code-in-javascript – Henders Aug 01 '16 at 11:37

1 Answers1

0
$value = var_export($myarray,true);
echo '<div id="#div_debug">'.$value.'</div>';

or:

$value = var_export($myarray,true);
echo "<script>$('#div_debug').html('.$value.');</script>"; 
Marouen Mhiri
  • 1,640
  • 1
  • 14
  • 20
  • the first way is working, but i want to change content of the div dynamically as the second way. I get the same error – Hobride Aug 01 '16 at 12:00
  • ok with this one: echo ""; (check the double quotes) – Marouen Mhiri Aug 01 '16 at 12:17
  • i'm sorry but this one tries to run the content of $value i get: SyntaxError: invalid arrow-function arguments (parentheses around the arrow-function may help) – Hobride Aug 01 '16 at 12:29