Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

call python scripts from php encoding error for chinese params

i call python script from my php,this is a demo

when i pass english params like "abcdxx", it's fine

when i pass chinese params like "天河"(even) the return is "天河"

when i pass chinese params like "天河区"(odd),the return is "天河åŒ?"

my php file

<?php

$param = "天河" //天河区    abc
$keyword = exec("jieba.py " . $param);
var_dump($keyword);

?>

my python file

#coding:utf-8
import sys
print sys.argv[1]
like image 835
user2538840 Avatar asked Jul 01 '26 16:07

user2538840


1 Answers

I have fixed the bug.

I don't how to solve this problem, but I used another way.

I urlencode params "天河" in php,then unquote "天河" in python, it's done.

like image 76
user2538840 Avatar answered Jul 04 '26 06:07

user2538840



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!