title: Displaying file_get_contents fails on special characters - PHP
body: <p>I am trying to open a file with <code>file_get_contents</code>. The file contains <code>"</code> and other special characters. When I try to output the contents of that file with <code>echo $file_contents</code> in <code>PHP</code>, the operation fails with <code>Unexpected token</code> errors. </p>
  
  <ol>
  <li>How can I encode such special characters?  </li>
  </ol>
  
  <p>Here is the code that gets the error: </p>
  
  <pre><code>&lt;?php
  //the function below displays data from bbMainPage javascript.
  function getDataFromLibrary() {
  
      $tgt_url = $_GET["tgt_url"];
      $file_contents = file_get_contents($tgt_url);
      //echo $tgt_url;
      //echo $file_contents;
      var_dump($file_contents);
      //return $tgt_url;
  }
  ?&gt;
  </code></pre>
  
  <p>Code in javascript: </p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;style&gt;
  .hlight{background-color:#ffcc00;}
  textarea {
      width:100%;
      height:100%;
  }
  &lt;/style&gt;
  &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  //mention all global variables here.
  console.log("this is the start of javascript");
  //get all data from the previous script.
  var fileContents = "&lt;?php getDataFromLibrary(); ?&gt;";
  var tgtURL = &lt;?php echo json_encode($tgt_url); ?&gt;;
  
  console.log("URl obtained = " + tgtURL);
  console.log("Text obtained = " + fileContents);   //this is where it fails.
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;/html&gt;
  </code></pre>