Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

added 481 characters in body
Source Link
Niet the Dark Absol
  • 325.7k
  • 86
  • 480
  • 604

Try this:

var loc = <?php echo json_encode($loc); ?>;

You should not use print_r. Let me quote the documentation :

print_r — Prints human-readable information about a variable

Note the part I emphasised. "human-readable". Just because it looks vaguely like something JavaScript might understand, doesn't mean it is ;) json_encode , on the other hand, is specifically designed to output JSON, which is a subset of the syntax JavaScript accepts for variables.

Try this:

var loc = <?php echo json_encode($loc); ?>;

Try this:

var loc = <?php echo json_encode($loc); ?>;

You should not use print_r. Let me quote the documentation :

print_r — Prints human-readable information about a variable

Note the part I emphasised. "human-readable". Just because it looks vaguely like something JavaScript might understand, doesn't mean it is ;) json_encode , on the other hand, is specifically designed to output JSON, which is a subset of the syntax JavaScript accepts for variables.

Source Link
Niet the Dark Absol
  • 325.7k
  • 86
  • 480
  • 604

Try this:

var loc = <?php echo json_encode($loc); ?>;
default

AltStyle によって変換されたページ (->オリジナル) /