I need to pass a parameter into php code executed in python
import subprocess def php(code): p = subprocess.Popen(["php","-r", code], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out = p.communicate() #returns a tuple (stdoutdata, stderrdata) if out[1] != b'': raise Exception(out[1].decode('UTF-8')) return out[0].decode('UTF-8') val = str(1234) code = """ \ function my_encoder($in){ $out = base_convert($in,16,36); return ($out);} print(my_encoder('"""+{val}+"""')); """ print(php(code))
I don't know how to enter val as parameter of my_encoder function in php code.
If {
, } is not part of python's f-string, do not use it because This results in invalid syntax. So just remove these curly braces:
print(my_encoder('"""+val+"""')); """
The above is the detailed content of How to pass parameters into php executed in python?. For more information, please follow other related articles on the PHP Chinese website!