简体   繁体   English

PHP的回声/打印多行字符串?

[英]php Echo/printing a multiline string?

i have a php file launching my exe. 我有一个启动我的exe的php文件。 the exe does cout and the text is printed in html which is all fine. 该exe文件cout,并且文本以html打印,一切都很好。 until i write "someline\\n"; 直到我写下“ someline \\ n”; The \\n breaks the output and i only see the last line. \\ n中断输出,我只看到最后一行。 How do i print/echo text/strings that has multilines in them? 如何打印/回显包含多行的文本/字符串?

The current paste has \\n commented out and my text prints fine. 当前的粘贴内容已被\\ n注释掉,并且我的文本可以正常打印。 It looks ugly in the console and when i view source with IE7 (although i primarily browse with FF) the source is painful to look at. 它在控制台中看起来很丑陋,当我使用IE7查看源代码时(尽管我主要使用FF浏览),但查看源代码却很麻烦。 Here is my current php and cpp file 这是我当前的php和cpp文件

<html>
<head>
</head>
<body>
<?php
echo( exec('c:/path/to/exe/launchMe.exe hey lol hi') );
?>
</body>
</html>

cpp cpp

#include <string>
#include <iostream>
#include <sstream>
using namespace std;

const string htmlLine(string s)
{
    s+= "<br />";
//  s += "\n";
    return s;
}

int main(int argc, char *argv[])
{
    stringstream s;
    s << argc;
    cout << htmlLine("woot") << htmlLine(s.str());
    for (int i=0; i<argc; ++i)
    {
        s.str("");
        s << i << " = " << argv[i];
        cout << htmlLine(s.str());
    }
    return 0;
}

From http://php.net/exec : http://php.net/exec

Return Values 返回值

The last line from the result of the command. 命令结果的最后一行。 If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function. 如果您需要执行命令并直接将命令中的所有数据传回而不会受到任何干扰,请使用passthru()函数。

The exec() function only returns the last line of ouput, but passthru() returns all output. exec()函数仅返回输出的最后一行,而passthru()返回所有输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM