Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Universal examples regardless of browser or CLI #102

Open
timint opened this issue Sep 7, 2021 · 1 comment
Open

[Feature Request] Universal examples regardless of browser or CLI #102

timint opened this issue Sep 7, 2021 · 1 comment

Comments

@timint
Copy link

timint commented Sep 7, 2021

It's been extremely handy to use CLI with testing the examples.

I am here proposing a univeral way for both browser and CLI output:

<?php

  error_reporting(E_ALL);
  ini_set('display_errors', 'On');

  // Output handler
  ob_start(function($buffer){
    return (php_sapi_name() != 'cli') ? '<pre>'.htmlspecialchars($buffer).'</pre>' : $buffer;
  });

  // Do your stuff
  // ...

  var_dump('some output');

@timint
Copy link
Author

timint commented Sep 8, 2021

Or, if you are not gonna decorate the example pages then simply display plain text:

<?php

  error_reporting(E_ALL);
  ini_set('display_errors', 'On');

  header('Content-Type: text/plain; charset=utf-8');

  // Do your stuff
  // ...

  var_dump('some output');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant