pib
pib copied to clipboard
echo newline
Example code:
<?php
echo "foo\nbar";
it prints foobar
and it's not about html ignoring newline, the output is "foobar" in inspector.
Part of the issue is that pib is meant to support HTML output windows (e.g. it supports HTML tags). One way to fix this would be to add a setting to the menu to switch from HTML output to text output.
If you want to echo a newline, you'd have to echo "foo<br/>bar"
or use <p>foo</p><p>bar</p>
. I haven't checked why this isn't a space in pib. It could be the way webassembly forwards individual lines to JS, breaking on \n
, but I haven't confirmed that for pib.
https://tysonandre.github.io/phan-demo/ (for https://github.com/tysonandre/phan-demo) is a fork of this that always uses text output (instead of HTML) for running php programs (and adds a PHP static analyzer as an example of an application that can run in web-assembly). That may be a useful reference for implementing an alternative to treat CLI output as plaintext instead of HTML.
I've got a branch that solves this.
https://seanmorris.github.io/php-wasm/?code=%253C%253Fphp%250A%250Aprint%2520%2522Newlines%255Cn%255Cn%2522%253B%250Aprint%2520%27Seem%27%2520.%2520PHP_EOL%253B%250Aprint%2520%27to%2520be%2520working%2520now.%27%250A%2520%2520%2520%2520.%2520PHP_EOL%250A%2520%2520%2520%2520.%2520PHP_EOL%250A%2520%2520%2520%2520.%2520PHP_EOL%253B%250A%2520%2520%2520%2520%250Aprint%2520%27done.%27%253B&persist=0
@seanmorris maybe you should create PR, but I'm not sure if contribution are accepted.