1

Possible Duplicate:
What is the canonical way to determine commandline vs. http execution of a PHP script?

I am writing a small script that will executed as a cron job. Is there a way to understand if this script is called from a web server so that I could echo <br /> instead of newline character as output?

Community
  • 1
  • 1
yasar
  • 13,158
  • 28
  • 95
  • 160

2 Answers2

13

From php.net

if (PHP_SAPI === 'cli') 
{ 
    // ... 
} 
djdy
  • 6,779
  • 6
  • 38
  • 62
0

If the code has been called from the command line, the server variable HTTP_USER_AGENT is not set. Something like this might assist:

$newline = (isset($_SERVER['HTTP_USER_AGENT'])) ? "<br />" : "\n";
BenM
  • 52,573
  • 26
  • 113
  • 168