From f62fcd29a3486f9dc44d6e95945d49aed5c56f81 Mon Sep 17 00:00:00 2001 From: AllenJB Date: Sat, 4 Oct 2025 13:28:24 +0100 Subject: [PATCH] interactive-examples.js: Fix handling on newlines (multiple newlines collapsed) --- js/interactive-examples.js | 11 +++++------ js/php-web-README.md | 2 ++ 2 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 js/php-web-README.md diff --git a/js/interactive-examples.js b/js/interactive-examples.js index 7e67c952e3..7f2d41e90c 100644 --- a/js/interactive-examples.js +++ b/js/interactive-examples.js @@ -36,22 +36,21 @@ class PHP { if (PHP.runPhp) { return PHP.runPhp; } + let initializing = true; const { ccall } = await phpBinary({ print(data) { - if (!data) { + // The initial exec to get PHP version causes empty output we don't want + if (initializing) { return; } - - if (PHP.buffer.length) { - PHP.buffer.push("\n"); - } - PHP.buffer.push(data); + PHP.buffer.push(data + "\n"); }, }); PHP.version = ccall("phpw_exec", "string", ["string"], ["phpversion();"]), console.log("PHP wasm %s loaded.", PHP.version); + initializing = false; PHP.runPhp = (code) => ccall("phpw_run", null, ["string"], ["?>" + code]); return PHP.runPhp; } diff --git a/js/php-web-README.md b/js/php-web-README.md new file mode 100644 index 0000000000..125aa7709b --- /dev/null +++ b/js/php-web-README.md @@ -0,0 +1,2 @@ +These files are built by [emcripten](https://github.com/emscripten-core/emscripten) +via https://github.com/derickr/php-wasm-builder