I am running a php script from CLI command and web browser. I need to dispaly new lines properly in both ways so that it does not print "<br />"
in CLI and it shows new lines in browsers. Does anyone know how to write php function for this?
thanks for any helps
You could write a function to return the right thing based on the execution environment:
<?php
if (PHP_SAPI === 'cli')
{
return PHP_EOL;
}
else
{
return "<BR/>";
}
?>
You can set the output's content type to text/plain
to make browsers showing the content as, well, plain text like what you will see on CLI
header("Content-type: text/plain");
Put that before you output anything.
After that, always use \n
for new lines
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With