title: import php variables in javascript
body: <p>I have a file called english.php containing a tonne of variable values. All part of the <code>$LANG</code> array.</p>
  
  <p>Examples:</p>
  
  <p><code>$LANG['value_1']="abc";</code></p>
  
  <p><code>$LANG['value_2']="xyz";</code></p>
  
  <p>I then have a million different .php files that use <code>require_once('english.php');</code></p>
  
  <p>That is fine but I also have a lot of javascript and jquery plugins that I am using. They all have external .js files.  How can I get the values of <code>$LANG</code> in javascript to it is usable in the .js files?</p>
  
  <p>I guess I am gonna need to add code to the top of the .js to somehow reading the .php data before running the remainder of the javascript code. I just have absolutely no idea how to do that.</p>
  
  <p>I have seen a few possible ideas but I don't really want to do a major rewrite of everything. Looking for a simple solution. Can anyone help this clueless novice?</p>
  
  <p>======= Added more info based on comments received =======</p>
  
  <p>I now have a lang.php with this code in it...</p>
  
  <pre><code>&lt;?php
  session_cache_limiter('nocache');
  session_start();
  require_once ($_SESSION['language'].'.php');
  
  
  $js_out = json_encode($LANG);
  
  ?&gt;
  &lt;script&gt;
      var LANG = &lt;?php echo $js_out; ?&gt;;
      alert(LANG.value_1);
  &lt;/script&gt;
  </code></pre>
  
  <p>When I access the lang.php it successfully accesses english.php and alerts 'abc'</p>
  
  <p>My problem is that this does not work when added to a different file...</p>
  
  <pre><code>&lt;script type='text/javascript' src='lang.php'&gt;&lt;/script&gt;
  &lt;script&gt;
      alert(LANG.value_1);
  &lt;/script&gt;
  </code></pre>
  
  <p>======= Edited to add the SOLUTION =======</p>
  
  <p>Thanks to the comments of the people below, I got rid of the <code>&lt;script&gt;</code> in the lang.php file and it worked.</p>
  
  <p>I now have a lang.php with this code in it...</p>
  
  <pre><code>&lt;?php
  session_cache_limiter('nocache');
  session_start();
  require_once ($_SESSION['language'].'.php');
  
  
  $js_out = json_encode($LANG);
  
  ?&gt;
  
  var LANG = &lt;?php echo $js_out; ?&gt;;
  </code></pre>