shell_exec将多行输出显示为单行

我试图用 shell_exec()</ code>命令执行java文件,但是输出格式化 不符合预期。 以下是详细信息</ p>

代码:</ strong> </ p>

  echo shell_exec(“java WekaExample”); 
< / code> </ pre>

输出:</ strong> </ p>

  J48的准确度:50.00%-------  -------------------------- PART的准确性:50.00%------------------  --------------- DecisionTable的准确性:64.29%-----------------------------  ---- DecisionStump的准确性:21.43%--------------------------------- 
</ code> < / pre>

预期输出:</ strong>(在终端中运行命令时显示)</ p>

  J48的准确度:50.00%  


PART的准确度:50.00%


DecisionTable的准确性:64.29%


DecisionStump的准确性:21.43%


</ code> </ pre>

非常感谢任何类型的帮助。</ p>
</ div>

展开原文

原文

I am trying to execute java file using shell_exec() command, but the output formatting is not as per the expectation. Here are the details

code:

 echo shell_exec("java WekaExample");

output:

 Accuracy of J48: 50.00% --------------------------------- Accuracy of PART: 50.00% --------------------------------- Accuracy of DecisionTable: 64.29% --------------------------------- Accuracy of DecisionStump: 21.43% --------------------------------- 

Expected Output:(As displayed when running the command in terminal)

  Accuracy of J48: 50.00%
  ---------------------------------
  Accuracy of PART: 50.00%
  ---------------------------------
  Accuracy of DecisionTable: 64.29%
  ---------------------------------
  Accuracy of DecisionStump: 21.43%
  ---------------------------------

Any type of help is deeply appreciated.

dou11655853
dou11655853 你是对的 没有渲染。那么我怎样才能渲染输出,以便将 输出为<br>
4 年多之前 回复
duangan7834
duangan7834 如果是这种情况,请查看视图源并查看是否显示正确。浏览器通常需要HTML,因此 不会被渲染。
4 年多之前 回复
dongsu3138
dongsu3138 在网页上[Win/Linux并不重要]
4 年多之前 回复
douyujun0152
douyujun0152 你输出那个结果在哪里?Windows或Linux/Unix/Mac?
4 年多之前 回复

1个回答

I think you just need to convert the newlines (which probably really is there in the raw output) to <br /> tags for your browser to render them on separate lines. Use nl2br(), like:

echo nl2br(shell_exec("java WekaExample"));

Or put <pre></pre> tags around your output instead so the newlines are actually printed as new lines.

dtlzdofl66441
dtlzdofl66441 谢谢,解决了这个问题
4 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐