Sebastian
Sebastian

Reputation: 3628

Locally parsing PHP in the browser

I'm looking for a recommendation as to the best way of parsing PHP locally. Is there an add-on for Google Chrome that would mean I don't have to host a file in order to run the PHP?

Upvotes: 0

Views: 1925

Answers (7)

Dan Phillimore
Dan Phillimore

Reputation: 480

[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();
    });
});

Upvotes: 0

Ron
Ron

Reputation: 1336

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

Upvotes: 0

Bailey Parker
Bailey Parker

Reputation: 15905

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).

Upvotes: 0

jasonbar
jasonbar

Reputation: 13461

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.

Upvotes: 3

Inca
Inca

Reputation: 1901

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.

Upvotes: 0

nico
nico

Reputation: 51640

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

Upvotes: 3

Jon
Jon

Reputation: 437336

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.

Upvotes: 0

Related Questions