A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/oraoto/pib below:

oraoto/pib: PHP in Browser (powered by WebAssembly)

PIB: PHP in Browser (and Node.js) aka php-wasm

changelog

Install with npm:

You'll need to add the following postinstall script entry to your package.json to ensure the static assets are available to your web application. Make sure to replace public/ with the path to your public document root if necessary.

{
  "scripts": {
    "postinstall": [
      "cp node_modules/php-wasm/php-web.* public/"
    ]
  },
}

If you're using a more advanced bundler, use the vendor's documentation to learn how to move the files matching the following pattern to your public directory:

./node_modules/php-wasm/php-web.*

Using php-wasm is easy.

Once the library is included in the page, you can run PHP right from a script tag! The src attribute is also supported for non-inline scripts.

<script type = "text/php">
	<?php vrzno_run('alert', ['Hello, world!']);
</script>

First, grab an instance of the object:

const PHP = require('php-wasm/PhpWeb').PhpWeb;
const php = new PHP;

or, in es6:

import { PhpWeb as PHP } from 'php-wasm/PhpWeb';
const php = new PHP;

Then, add an output listener:

php.addEventListener('output', (event) => {
	console.log(event.detail);
});

Be sure to wait until your WASM is fully loaded, then run some PHP:

php.addEventListener('ready', () => {
	php.run('<?php echo "Hello, world!";');
});

Get the result code of your script with then():

php.addEventListener('ready', () => {
	php.run('<?php echo "Hello, world!";').then(retVal => {
		// retVal contains the return code.
	});
});

So long as php.refresh() is not called from Javascript, the instance will maintain its own persistent memory.

<?php
// Run this over and over again...
print ++$x;

See the example in action here

The DOM may be accessed via the VRZNO php extension. This is specially for the browser allowing PHP to access Javascript via a C api. It comes preinstalled with php-wasm.

See the example in action here

// Show an alert with vrzno_run. Note the second param is an array of args.
vrzno_run('alert', ['Hello, World!']);

$oldTitle = NULL;
$newTitle = 'Changed@' . date('h:i:s');

// Grab the current title.
$oldTitle = vrzno_eval('document.title');

// Change the document title.
vrzno_eval('document.title = "' . $newTitle . '"' );
php-wasm is a fork of oraoto/PIB...

Run PIB

Firefox is recommended for better user experience.

The quickest way to build PIB is by using Make & Docker. Simply issue the make command after checking out the repo, and it will build.

Using Emscripten SDK (emsdk) manually

Steps:


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.3