乐趣区

在浏览器里面执行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"], );
        /* 值为 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 把资源爬下来

退出移动版