【发布时间】:2011-07-07 09:41:39
【问题描述】:
我在 index.html 文件中有这个表单。
<form method="post" action="index.php" accept-charset="UTF-8">
<input id="a" name="a" type="text">
<input type="submit" name="run_query" value="Add User" size="30">
</form>
我正在尝试通过将以下 php 代码嵌入到 index.html 文件中,将文本输入作为参数传递给 pyton 脚本:
<?
session_start();
ob_start();
if(isset($_REQUEST['run_query'])) {
$add_user = $_REQUEST['a'];
$command = "add_author.py $add_user";
exec($command);
}
?>
我已将 add_author.py 文件放入 index.html 所在的同一文件夹中。它适用于任何字符串。但是如果我尝试使用包含 ä ö é 的字符串,它就不起作用了。
python 文件如下所示。
import sys
import codecs
if __name__ == '__main__':
wFile = codecs.open("test.txt", "w", "utf8")
wFile.write(" ".join(sys.argv[1:]))
wFile.close()
顺便说一句:index.html 中有这一行。
<meta charset="utf-8" />
我很想听到更好的方法来管理我的任务或纠正我的方法。谢谢!
【问题讨论】:
-
什么是操作系统?系统编码是什么?
标签: php python html encoding utf-8