HTML中如何通过PHP调用C++

发布时间:2021-10-19 10:10:02 作者:小新
来源:亿速云 阅读:181

这篇文章给大家分享的是有关HTML中如何通过PHP调用C++ 的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

一、在本地服务器目录下新建一个 test 文件夹,在此文件夹中新建文件:

   1. cpp.html

<!DOCTYPE html>
<html>
<head>
<title>C++测试</title>
</head>
<body>
    <form method="post" action="cpp.php">
    <div>
        <p>请测试文字,以空格分隔:</p>
        <input type="text" name="arr" size="20" />
        <input type="submit" value="确定" />
    </div>
    </form>
</body>
</html>

   2. cpp.php

<?php
$arr = $_POST['arr'];
if(empty($arr)){
    echo "You didn't enter any arguments.";
}
else{
    $command = " test " . escapeshellcmd($arr);
    $return = passthru($command);
}
?>

二、新建 test.cpp 文件,编译运行后,将生成的 test.exe 文件复制到上一步创建的test文件夹下;

#include <iostream>
#include <stdio.h>
using namespace std;
int main(int argc, char* argv[])
{
    cout<<endl<<"You passed "<<argc-1<<" arguement"<<(argc-1==1?"":"s")<<"."<< endl;
    cout<<(argc-1==1?"This":"These")<<"arguement"<<(argc-1==1?"":"s")<<" "<<(argc-1==1?"is":"are")<<":"<< endl << endl;
    for (int i = 1; i<argc;i++)
        cout<<argv[i]<<endl;
    return 0;
}

三、在浏览器中打开 cpp.html

感谢各位的阅读!关于“HTML中如何通过PHP调用C++ ”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

推荐阅读:
  1. HTML如何调用PHP
  2. html调用php文件的方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php html c++

上一篇:php调用接口流程是怎么样的

下一篇:linux中php date错误怎么办

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》