<script src="file.js" type="text/javascript" charset="utf-8"> </script> Inside file.js is var a = "somedata" How do I make php echo the variable a from file.js?
<script src="file.js" type="text/javascript" charset="utf-8"> </script > <script type="text/javascript" charset="utf-8"> document.write(a); </script>
This wouldn't be reccomended as typically PHP serves the data to output JavaScript and HTML, not the other way round. However, if you want to take data from the user and do something with it (i.e. perform a PHP function on it) then you could use Ajax for this. PHP could never go on to echo this information though, it could only parse it, JavaScript would echo it.
//Get content $file = 'file.js'; $f = fopen($file,'r'); while($c = fread($f,10256547)){ $total .= $c; } fclose($f); //Find match and echo it preg_match('/.*var a="(.*)".*/iUs',$total,$result); print_r($result); PHP: Peace,