Wenn Python und PHP sind ausgestattet Berücksichtigen Sie auf demselben Server einen einfachen Dateiexport/Import t, wobei die XML-Inhalt in einen String umgewandelt und als Datei aus Python gespeichert und lesen dann in PHP:
Python
import xml.etree.ElementTree as ET
xmlstr = '''\
<data>
<example>88</example>
</data>'''
dom = ET.fromstring(xmlstr)
tree_out = ET.tostring(dom, encoding='UTF-8', method='xml')
xmlfile = open('/path/to/Output.xml', 'wb')
xmlfile.write(tree_out)
xmlfile.close()
PHP
// LOAD XML SOURCE
$doc = new DOMDocument();
$doc->load('/path/to/Output.xml');
// ECHO CONTENT
echo $doc->saveXML();
Befehl Linie
Sie können sogar das Python-Skript über die Befehlszeile von PHP aufrufen exec()
mit:
exec('python /path/to/Python/Script.py');
// LOAD XML SOURCE
$doc = new DOMDocument();
$doc->load('/path/to/Output.xml');
// ECHO CONTENT
echo $doc->saveXML();
//<?xml version="1.0"?>
//<data>
// <example>88</example>
// </data>
Und umgekehrt von Python subprocess die mit call
oder Popen
import subprocess
#... same as above ...
# RUN CHILD PROCESS W/O OUTPUT
subprocess.call(['php', '/path/to/PHP/Script.php'])
# RUN CHILD PROCESS W/ OUTPUT
proc = subprocess.Popen(['php','/path/to/PHP/Script.php'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
print(stdout.decode("utf-8"))
#<?xml version="1.0"?>
#<data>
# <example>88</example>
# </data>
Ich glaube, Sie ein kleines Python erstellen haben Server, der die XML-Datei bereitstellt. https://docs.python.org/2/library/simpletttpserver.html – wrufesh
Warum speichern Sie nicht XML von Python auf die Festplatte und lesen Sie in PHP? – Parfait