oraoto / pib

PHP in Browser (powered by WebAssembly)
https://oraoto.github.io/pib/
Apache License 2.0
953 stars 109 forks source link

echo newline #41

Open jcubic opened 4 years ago

jcubic commented 4 years ago

Example code:

<?php

echo "foo\nbar";

it prints foobar and it's not about html ignoring newline, the output is "foobar" in inspector.

TysonAndre commented 4 years ago

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.

seanmorris commented 4 years ago

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

jcubic commented 4 years ago

@seanmorris maybe you should create PR, but I'm not sure if contribution are accepted.