Echoing PHP into a JS variable stops rest of script from executing?
<p>I'm attempting to echo a PHP variable into my script, however it seems to break the rest of the script:</p>

<p><strong>Here's my PHP:</strong></p>

<pre><code>$geo_options = "&lt;option value=\"0\"&gt;Select country&lt;/option&gt;
&lt;option value=\"AF\"&gt;Afghanistan&lt;/option&gt;
&lt;option value=\"AL\"&gt;Albania&lt;/option&gt;
&lt;option value=\"DZ\"&gt;Algeria&lt;/option&gt;
&lt;option value=\"AS\"&gt;American Samoa&lt;/option&gt;
&lt;option value=\"AD\"&gt;Andorra&lt;/option&gt;
&lt;option value=\"AG\"&gt;Angola&lt;/option&gt;
...";
</code></pre>

<p><strong>And my Javascript/jQuery:</strong></p>

<pre><code>$(document).ready( function() {
    var id = $(this).val();

    function countProperties(obj) {
      var prop;
      var propCount = 0;

      for (prop in obj) {
        propCount++;
      }
      return propCount;
    }
      var options = "&lt;?php echo $geo_options; ?&gt;";
      $('#geo-location').append(options);
      $.get('json.php',
        function(data) {
            $('input[name=url]').val(data.url);
            $('select[name=r_id]').prepend("&lt;option selected='selected' value='" + data.rid + "'&gt;" + data.rname + "&lt;/option&gt;");
            $('input[name=r_min]').val(data.rmin); $('input[name=r_max]').val(data.rmax);
            if(data.blank == 1) {
            $('input[name=blank]').attr("checked", "checked"); 
            }

            var geo = (countProperties(data)-5)/2;


            }, 'json');

    });
</code></pre>

<p>If I comment out <code>var options = '&lt;?php echo $geo_options; ?&gt;';</code> so this must be the part stopping the rest of the script from executing correctly (from that point downwards, as even <code>$('#geo-location').append();</code> doesn't work).</p>

<p>I just can't figure out why this would be though?</p>

<p>Any help, would be greatly appreciated.</p>

<p><em>(Note: I've attempted to use both <code>'</code> single quotes and <code>"</code> double quotes to encase the variable, thinking that the escapes in the string might be the problem, but neither have made a difference).</em></p>

<p><strong>Update:</strong></p>

<p>I've now placed my entire code, both JS and HTML into a JSFiddle as I figure there might be something I haven't spotted at all. To recap on what I've tried so far; using different quote types (single, double, none), re-escaping the variable <code>$geo_options</code> with <code>add_slashes()</code>, <code>str_replace()</code> and <code>json_encode()</code>, echoing the variable <code>$geo_options</code> into a random HTML element, which worked fine.</p>

<p>My JsFiddle: <a href="http://jsfiddle.net/SFwB6/" rel="nofollow">http://jsfiddle.net/SFwB6/</a></p>

<p>I must confess, I'm totally stumped.</p>

<p><strong>Update 2:</strong></p>

<p>I've attempted to make it much easier, and place the entire <code>$geo_options</code> string in <code>var options</code> from the beginning; <a href="http://jsfiddle.net/NUCRG/" rel="nofollow">http://jsfiddle.net/NUCRG/</a>.</p>

<p>However, both JSLint and Dreamweaver display a syntax error, but I'm not sure why. Perhaps this is the root of the problem?</p>
