Jump to content

Sending PHP variables to Javascript


Kodak07

Recommended Posts

I am writing an app where im using PHP to parse out a file then i need to push some of the parsed file to a javascript function (google maps javascript to be exact)

 

 

PHP SECTION

<?php

while(!feof($file))

{

  $line = fgets($file);

 

  $temp = explode(" ", $line);

 

  if ($temp[0]=="latitude:")

    {

  $lat = $temp[1];

  echo $lat;

 

}

 

  if ($temp[0]=="longitude:")

    {

  $long = $temp[1];

  echo $long;

 

}

}

fclose($file);

?>

 

Javascript Function

function initialize() {

      if (GBrowserIsCompatible()) {

        var map = new GMap2(document.getElementById("map_canvas"));

        map.setCenter(new GLatLng(37.4419, -122.1419), 13);  I need my php variables to replace these numbers

      }

    }

 

Thanks for the help :)

Link to comment
https://forums.phpfreaks.com/topic/99079-sending-php-variables-to-javascript/
Share on other sites

try this

function initialize() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(<?php echo $lat;?>, <?php echo $long;?>), 13);  I need my php variables to replace these numbers
      }
    }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.