Jump to content

Recommended Posts

<?php

$d=date ("D m");

if ($d="sept07");

  echo "it's fall";

else

  echo "it's not fall";

 ?>

 

it's small but hey it's my first day.

 

but I get this error

 

Parse error: syntax error, unexpected T_ELSE in /home/theweath/public_html/dustintest/dustintestphp.php on line 5

 

Thoughts?

Link to comment
https://forums.phpfreaks.com/topic/67964-solved-php-error/
Share on other sites

yea it was fine.

 

it just had some fillers or something when I copied it. I got it working with this code.

 

<?php
$d==date ("DM");
if ($d=="oct 28th")
  echo "it is fall";
else
  echo "it is not fall";
?>

 

Question for you folks is... how do you make it say it is fall?

Link to comment
https://forums.phpfreaks.com/topic/67964-solved-php-error/#findComment-341652
Share on other sites

$d==date ("DM");

 

should be:

$d=date ("DM");

 

The "DM" u used in date() make no sense for what u are aiming. "D" will give u "Mon", "Tue" etc. The full "DM" will give u for today: "Wed Sep". For lets say "Oct 28" u will need "M j" where "j" is the day of the month without leading zeros.

Link to comment
https://forums.phpfreaks.com/topic/67964-solved-php-error/#findComment-341661
Share on other sites

so when oct 28th comes around the message will change? how does it know that?

 

The script is such that when the date is 28 October it will print the message, otherwise print the other message. The full one should be:

 

<?php
$d = date("M j");
if($d == "Oct 28"){
  echo "it's fall";
} else{
  echo "it's not fall";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/67964-solved-php-error/#findComment-341662
Share on other sites

exactly what the code says when $d == date ("D,M"); which shows today's date.  if you wanna try it try this code

<?php
$d=date ("M j");
if ($d=="Sep 4"){
  echo "it is 9/4";
}else{
  echo "it isnt 9/4";}

?>

 

What's the difference of this to mine code?

Link to comment
https://forums.phpfreaks.com/topic/67964-solved-php-error/#findComment-341672
Share on other sites

my code has it passing on sept 4th and failing every other date so he can see what happens when it passes.

 

The codes are totally alike with a string of difference. Anyway not that it really matters.

 

@d22552000, id say good point. Probably he can use smth like:

 

$date = date("M j");
list($month, $day) = explode(' ', $date);
$day = intval($day);
if($month == 'Sept' and $day >= 7){
    echo "It is Fall";
} else{
    echo "No its not";
}

 

Or whatever like that which makes it work.

Link to comment
https://forums.phpfreaks.com/topic/67964-solved-php-error/#findComment-341683
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.