开发者

Locally parsing PHP in the browser

I'm looking for a recommendation as to the best way of parsing PHP locally. Is ther开发者_如何学Pythone an add-on for Google Chrome that would mean I don't have to host a file in order to run the PHP?


PHP is executed by the PHP processor, not your browser.

You need to have a webserver and PHP running on your local machine. On Windows, WAMP is a popular (and easy) way to get this development stack up and running.

You can find any number of tutorials for getting the LAMP stack setup on Linux.


Just install a webserver. Apache is a good choice or, if you're under Windows, you can also consider IIS.


What you want is not possible. PHP is a server-side scripting language.

As an aside, parsing PHP would be possible in the browser. Executing the code would not.


For Google Chrome I don't know, but you can run php from the command line, run a local server (if you're on Windows, Wamp or Xamp are easy to install). And several IDE's (NetBeans php for one) have the option of executing files locally from your IDE.


Why not try XAMPP? It's easy to install, maintain, use as a debugging environment. If you have a spare computer laying around, you may also consider setting up a dedicated testing server with a Ubuntu LiveCD. There's a bit of a learner's curve if your used to Window's GUI, but you can do some amazing things with a Linux box. Once you setup a server, you can point to it in Chrome with it's LAN IP or with http://localhost/ (if you installed XAMPP on your computer).


Have a look at this project: http://phpjs.hertzen.com/ (This is for People who stumbled over this Question via Goole)


[Disclaimer: I am the author.]

Uniter allows you to parse and execute PHP in the browser (or Node.js.)

http://asmblah.github.io/uniter/

Example code could be like the following:

require([
    'uniter'
], function (
    uniter
) {
    'use strict';

    var phpEngine = uniter.createEngine('PHP');

    function output() {
        console.log(phpEngine.getStdout().readAll());
        console.log(phpEngine.getStderr().readAll());
    }

    phpEngine.expose({
        number1: 7
    }, 'myData');

    phpEngine.execute('<?php return $myData->number1 + 2;').done(function (value) {
        output();

        console.log('Result: ' + value);
    }).fail(function (exception) {
        output();
    });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜