【发布时间】:2020-06-24 02:18:55
【问题描述】:
我目前有从 python 文件输出数据的 php 代码。这是成功运行的输出。
Total = 11 Number of Correct Answers = 4 Percentage Correct = 36.36363636363637 % Number of Incorrect Answers = 7 Percentage Wrong = 63.63636363636363 % [['0' '1' '2'] ['0' '3' '13'] ['0' '4' '14'] ['0' '2' '8'] ['1' '2' '6'] ['0' '4' '18'] ['1' '1' '2'] ['0' '2' '7'] ['0' '3' '14'] ['0' '2' '7'] ['0' '1' '2']] [1 0 1 0 0 0 1 0 0 1 0] probabilities [[0.47642793 0.52357207] [0.94137447 0.05862553] [0.95579032 0.04420968] [0.81265167 0.18734833] [0.7674815 0.2325185 ] [0.98345533 0.01654467] [0.53448523 0.46551477] [0.77109059 0.22890941] [0.95386825 0.04613175] [0.77109059 0.22890941] [0.47642793 0.52357207]]
我不知道如何在我的 php 页面上重新格式化这个输出。显然,当您在终端中运行 py 文件时,它的格式非常完美。我想要有适当的换行符。类似的东西
Total = 11
Number of Correct Answers
Percentage Correct.
我尝试在实际的 py 文件中实现换行,但是当 php 文件从 py 文件中输出数据时,它总是出现在上面的场景中。
这是我的代码:
php-
<?php
$email = $_SESSION['email'];
$command = escapeshellcmd("C:/Python38/python.exe C:/xampp/htdocs/Ensemble/login/test.py $email");
$output = shell_exec("$command 2>&1");
print($output);
?>
py:
print("Total =", len(training_set))
print("Number of Correct Answers =", len(correct))
print("Percentage Correct =", 1.*len(correct)/len(training_set)*100.0, "%")
print("Number of Incorrect Answers =", len(incorrect))
print("Percentage Wrong =", 1.*len(incorrect)/len(training_set)*100.0, "%")
(矩阵有更多输出,但我试图首先关注这些 py 元素)。
【问题讨论】:
-
如果你用 HTML 显示它,那么你必须用
<br>代替\n- 因为 HTML 不关心\n(新行) - 你可以在PHP 与 nl2br。或者您必须在<code> your text </code>中显示它才能将\n显示为新行。
标签: python php formatting backend web-development-server