<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>php</title>
</head>
<body>
<textarea rows="10" cols="100" id="code">
<?php
echo date('Y-m-d H:i:s');
?>
</textarea>
<p><button>run php code</button></p>
<script type="text/javascript" src="php.js" async></script>
<script type="text/javascript">
document.querySelector('button').addEventListener('click', function(){

    function init()
    {
        let code = document.getElementById("code").value;
        code = code.replace(/^\s*<\?php/, "");
        code = code + "\necho PHP_EOL;";
        let result = phpModule.ccall('pib_eval', 'number', ["string"], [code]);
        /*值为0表示成功*/
        console.log("run=" + result);
    }

    var config = {
        postRun: [init],
        print: function(text){
            console.log(text);
        },
        printErr: function(text){
            console.log(text);
        }
    };

    var phpModule = PHP(config);
});
</script>
</body>
</html>

可以去https://xxfaxy.gitee.io/pib/index.html把资源爬下来


xxfaxy
1.6k 声望18 粉丝