Main reference two articles
A line break in PHP
Debugging Python with PHP
Python peek-the beginner to Python
These two articles combine to test, the main process is as follows
cd/var/www/htmlmkdir Scriptnano script/test.py# paste code nano test002.php# paste code
The main problems encountered during the period are
PHP file inside the path/script/test.py, changed to script/test.py, the author obviously added directories in the root directory
PHP for the implementation of the line, want to achieve, originally with \ n, the result of failure, so with <br>
Continue to modify, found that the continuous iteration of the statement can not print the data, the specific reason is not queried, guessing is due to the Python itself error, you can run the script test locally.
Another test is the Chinese language support, found in Chinese when the page is blank, is obviously an error, it was expected that PHP is not good for Chinese support, so modified, added Chinese support, found that the situation is still, so the local test of Python Chinese support, found not supported, according to the error message
' \xe8 ' in file test.py on line 9, but no Encodi
Query the workaround. Originally need to start adding UTF8 support, add line comments done, the final PHP script content is
<?PHP#header ("content-type:text/html; Charset=utf-8 ");$output=shell_exec(' Python script/test.py ');$array=Explode(‘,‘,$output);foreach($array as $value) {#echo "\ n";Echo $value;Echo"<br>";}?>
Python content is
#Coding=utf-8Print 'This was a Python program with PHP,'#print ' \ n 'Print ","Print ","Print ","Print ","Print ","Print 'Write A program This prints the numbers from 1 to 100. Multiples of three print "Fizz" instead of the number and for the multiples of five $Print 'Requirements: Printing 1 to 100, encountered a multiple of 3, only print "Fizz", encountered a multiple of 5, print "Buzz", while encountering multiples of 3,5, print "Fizzbuzz",' forXinchRange (1,101):Print"Fizz"[x%3*4:]+"Buzz"[X%5*4:]orxPrint "," forXinchRange (1,11):Print"Qiangge_is_god"[x%3*14:]+"I_can ' T_believe_it"[X%5*18:]orxPrint ","False=TrueifFalse:Print "Hello"Else: Print " World"Print ','
The last displayed
PHP calls Python script