0
    <?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!!


Azeem Hassni
  • 885
  • 13
  • 28
PHP Learner
  • 111
  • 2
  • 4
  • 15
  • 2
    What line gives the error? – David Aug 13 '14 at 12:27
  • try to change this `$days=cal_days_in_month(CAL_GREGORIAN, $mm, $year);` to `$days=cal_days_in_month(0, $mm, $year);` – Azeem Hassni Aug 13 '14 at 12:29
  • I have simply copied your code and run it there is no error.tell where you are getting the error. – Suchit kumar Aug 13 '14 at 12:30
  • The error is pretty common. It means that you have a typo, or are using a constant that isn't defined. PHP defaults to interpreting that piece of quote as though it were quoted (ie a string literal). To fix: make sure the `CAL_GREGORIAN` constant exists (`var_dump(defined('CAL_GREGORIAN'));`), check if you didn't omit a `$` sign somewhere, and ensure you have no typo's in any functions you call. Also check the file encoding, the code is best saved as UTF-8 – Elias Van Ootegem Aug 13 '14 at 12:33
  • it shows in this line $to = date('Y-m-d 23:59:59',strtotime($from.$dayys)); – PHP Learner Aug 13 '14 at 12:33
  • var_dump(defined('CAL_GREGORIAN')); it shows bool(true) – PHP Learner Aug 13 '14 at 12:35

2 Answers2

5

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));
Rakesh Shetty
  • 4,548
  • 7
  • 40
  • 79
dano
  • 1,043
  • 1
  • 6
  • 11
  • i encoded it in ANSI and saw it echo "Last".date('Y-m-d 23:59:59',strtotime($var));​ – dano Aug 13 '14 at 12:33
  • i didn't get like that – PHP Learner Aug 13 '14 at 12:39
  • WOW!! i got rectified that issue....but i have a question,both lines are same but how i can got the answer with out that issue – PHP Learner Aug 13 '14 at 12:43
  • whatever encoding your text editor was using just couldn't read that character. All i did was comment lines out starting from the bottom until it worked, then i could start narrowing down possibilities. And then i rewrote the line by hand, and it worked. So i figured there was an encoding issue. In notepad++ you can go to 'Encoding' -> Convert to ____ to check out different character sets – dano Aug 13 '14 at 12:45
  • 1
    That "weird" character, is a Unicode Character 'ZERO WIDTH SPACE' (U+200B) - See this Q&A http://stackoverflow.com/q/2973698/ – Funk Forty Niner Aug 13 '14 at 12:59
  • Good to know thanks! Don't know my character encodings well enough clearly! – dano Aug 13 '14 at 13:06
  • You have told about the notepad++, in that "convert to ________", fill that dash ji....because there is lot of options in encoding option..by selecting which option i can remove that space – PHP Learner Aug 14 '14 at 08:21
0

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));
Azeem Hassni
  • 885
  • 13
  • 28
  • Sidenote: Your answer would not have worked, because it too contains the OP's Unicode Character 'ZERO WIDTH SPACE' (U+200B) as stated in [`my comment`](http://stackoverflow.com/questions/25286083/use-of-undefined-constant-assumed-in-php#comment39406746_25286250). – Funk Forty Niner Aug 13 '14 at 13:03