函数内部的PHP if语句


PHP if statement inside function

<?php
  function win_bsd(){
    if (strncasecmp(PHP_OS, 'WIN', 3) == 0) {
      echo 'This is a server using Windows!';
    } else {
      echo 'This is a server not using Windows!';
  }
?>

为什么这个不起作用,如果我不把它设置为一个函数,它确实起作用。然而,当我把它设置为一个函数时,它会给我错误。

分析错误:语法错误,C:''examplep''htdocs''shell ''shell2.php中第198行出现意外的文件结尾

检查右括号。

<?php
  function win_bsd()
  {
      if (strncasecmp(PHP_OS, 'WIN', 3) == 0) 
      {
          echo 'This is a server using Windows!';
      }
      else 
      {
          echo 'This is a server not using Windows!';
      }
  }
?>