使用未定义的常量 ? - 假设'?' 在 php 中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25286083/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:45:54  来源:igfitidea点击:

Use of undefined constant ? - assumed '?' in php

php

提问by PHP Learner

    <?php
         $f=$_POST['rdate'];
          echo $f."</br>";
           $from=$f.'-01 00:00:00';
           $dayyy=explode("-",$f);
           //print_r($dayyy);
           $year=$dayyy[0];
           echo $year."</br>";
           $mm=$dayyy[1];   
            echo $mm."</br>";
        $mons = array("01" => "Janauary", "02" => "February", "03"=>"March", "04"=>"April", "05"=>"May", "06"=>"June", "07"=>"July", "08"=>"August", "09"=>"September", "10"=>"October", "11"=>"November", "12"=>"December");
        print_r($mons);
        /*foreach($mons as $mm)
        {
          echo $mm; 
        }*/
        $month_name = $mons[$mm];
        echo "</br>".$month_name;
      $days=cal_days_in_month(CAL_GREGORIAN, $mm, $year);
        $dayss= $days-1;
        echo $dayss."</br>";
        $dayys=' + '.$dayss.' days' ;
        $var=$from.$dayys;
        //echo $var."</br>";
        echo "Last".date('Y-m-d 23:59:59',strtotime($var));?

        ?>

i'm getting Use of undefined constant ? - assumed error in the above code. I guess i got this issue due to non breaking spce but don't know where i left that? Kindly help!!

我正在使用未定义的常量?- 上面代码中的假设错误。我想我是因为没有破坏 spce 而遇到这个问题的,但不知道我把它放在哪里了?请帮忙!!



回答by dano

You have some kind of weird character on your

你身上有某种奇怪的性格

echo "Last".date('Y-m-d 23:59:59',strtotime($var));

line notepad++ couldn't see it but when I tried to arrow throw it, it went through twice.

行记事本++看不到它,但是当我尝试用箭头扔它时,它经历了两次。

Anyways, remove the line and copy and paste this

无论如何,删除该行并复制并粘贴

echo "Last".date('Y-m-d 23:59:59',strtotime($var));

回答by Azeem Hassni

check the constant you are using is defined or not .. if not define it

检查您正在使用的常量是否已定义.. 如果没有定义它

the code will be

代码将是

<?php 

  if (!defined('CAL_GREGORIAN')) 
    define('CAL_GREGORIAN', 0); 

   $f=$_POST['rdate'];
          echo $f."</br>";
           $from=$f.'-01 00:00:00';
           $dayyy=explode("-",$f);
           //print_r($dayyy);
           $year=$dayyy[0];
           echo $year."</br>";
           $mm=$dayyy[1];   
            echo $mm."</br>";
        $mons = array("01" => "Janauary", "02" => "February", "03"=>"March", "04"=>"April", "05"=>"May", "06"=>"June", "07"=>"July", "08"=>"August", "09"=>"September", "10"=>"October", "11"=>"November", "12"=>"December");
        print_r($mons);
        /*foreach($mons as $mm)
        {
          echo $mm; 
        }*/
        $month_name = $mons[$mm];
        echo "</br>".$month_name;
      $days=cal_days_in_month(CAL_GREGORIAN, $mm, $year);
        $dayss= $days-1;
        echo $dayss."</br>";
        $dayys=' + '.$dayss.' days' ;
        $var=$from.$dayys;
        //echo $var."</br>";
        echo "Last".date('Y-m-d 23:59:59',strtotime($var));