0

Is somehow possible to put javascript variable in eval echo? I tried a lot of possibilities, but everything crashed. It can work without Eval() function, but in that way, you can't quote "cal_days_in_month".

 <script>
     for (var i = 1; i < <?php eval("echo cal_days_in_month(CAL_GREGORIAN, ".'<script>variable</script>'." , 2022) + 1;");?>; i++) {

       if (i==8 || i == 15 || i == 22 || i == 29) { //10 19 28
      document.write("<tr>");
       }

    document.write("<td class='cc'>"+ i +"</td>");
   }

      document.write("<tr>");  //konec else závorka

     </script>

Calendar look with hard-written variable

Reporter
  • 3,897
  • 5
  • 33
  • 47
n p
  • 1
  • 2
  • What is the use case and what is the expected output? – Reporter Jul 25 '22 at 07:14
  • What is `eval` doing in here? – tadman Jul 25 '22 at 07:15
  • 4
    PHP receives variables *only* during the request processing. It has *absolutely no* access to the JavaScript runtime inside the browser that, if this is a page load request, may not even be running yet. Send this in as a variable you can retrieve via `$_GET` or `$_POST`. – tadman Jul 25 '22 at 07:16
  • It's calendar in slideshow container with 12 slides, each slide for each month – n p Jul 25 '22 at 07:16
  • If this is a calendar, find a JavaScript snippet that does what you want. These calculations aren't hard. There's a ton of code on NPM. – tadman Jul 25 '22 at 07:18
  • there you just need a way to get the number of days in a given month in javascript clientside... for example you have your solution here: https://stackoverflow.com/questions/1184334/get-number-days-in-a-specified-month-using-javascript : `new Date(year, month, 0).getDate();` – Diego D Jul 25 '22 at 07:25
  • https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming – oLDo Jul 25 '22 at 07:45
  • Does this answer your question? [How do I pass variables and data from PHP to JavaScript?](https://stackoverflow.com/questions/23740548/how-do-i-pass-variables-and-data-from-php-to-javascript) – Justinas Jul 25 '22 at 07:57

0 Answers0