0

When I have simple calls functions in PHP (such as file_exists() and others) from Javascript, it works:

console.log("<?php echo file_exists('img.png');?>");

But when involving quotes, it fails.

s='img.png';
console.log("<?php echo file_exists('"+s+"');?>");

How should I escape this to making the last line work?

Brethlosze
  • 1,452
  • 17
  • 36
  • 1
    um, it's the most useful thing you could possibly try to understand, given what you are asking here. You *cannot* have PHP evaluate the content of a Javascript variable, as the only way you can communicate that information from the client (where the JS variable lives) to the server (where PHP lives and runs) is by sending another HTTP request. There is no means of "escaping quotes" that will get your code to do what you want, and that question I pointed you towards is the best explanation on SO as to why this can't work. – Robin Zigmond Apr 12 '22 at 19:03

0 Answers0