在瀏覽器裏面執行PHP

<!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把資源爬下來

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章