将参数从php发送到c ++

时间:2017-05-17 11:26:47

标签: php c++

由于exec函数,我想从PHP向cpp.exe发送一些字符串参数。 exe的目的是根据查询计算文档的等级。

以下是php中的代码:

 $query = "is strong";
    $file = "vsm.exe $query";
    exec($file,$out);
    echo $out[0];`

我收到了echo $ out [0];

的输出
  

注意:未定义的偏移量:第25行的C:\ xampp \ htdocs \ analysis.php中的0

但是,当查询没有空格时,我的vsm.exe只能工作(这意味着我在$ out变量中获得了我的排名,这是正常的):

 $query = "is";
    $file = "vsm.exe $query";
    exec($file,$out);
    echo $out[0];

我按照那个使用整数参数的例子(这不是我想要的,我想发送句子):

 $a = 2;
    $b = 5;
    exec("tryphp.exe $a $b",$c_output);
    echo $c_output[0];
    $c_array0 = explode(" ",$c_output[0]);
    echo "Output: " . ($c_array0[0] + 1); 
    echo "Output: " . ($c_output[0] + 1);

如何将包含空格(可能是长文本)的字符串作为c ++的参数发送? 提前致谢。

1 个答案:

答案 0 :(得分:0)

我实际上找到了一些但仍然不够好的东西: $query = "is strong"; $file = 'vsm.exe "is strong"'; exec($file,$out); echo $out[0];

它返回了我想要的等级。但是,我寻找一种方法来使用$ query作为参数,而不是直接使用字符串"是强大的"。