[php将JavaScript变量回显到file.txt

问题描述 投票:0回答:1

我拥有这段代码,可以很好地获取用户时区并在php中回显。之前也有警报消息。

<script type="text/javascript"
src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js">
</script> <script> var timezone =
Intl.DateTimeFormat().resolvedOptions().timeZone; alert(timezone);
</script>
<?php
$time= "<script>document.writeln(timezone);</script>";
echo $time;

我想将此回声存储在文件time.txt中

我已经尝试过:

$file_name = 'time.txt';
//opens the file.txt file or implicitly creates the file
$myfile = fopen($file_name, 'w') or die('Cannot open file: '.$file_name);
// write name to the file
fwrite($myfile, $time);
// close the file
fclose($myfile);

但是它不起作用。

任何解决方案?

javascript php echo fwrite fputs
1个回答
1
投票

[PHP似乎想要用时区变量的结果写入文件,即它将是一个带有时区名称的文本文件。

© www.soinside.com 2019 - 2024. All rights reserved.