Any PHP wizards out there?

Kreskin

Doctor of Thinkology
Feb 23, 2006
21,155
149
63
Andem is probably sleeping now so thought I'd see if any other wizards are around.
 

scratch

Senate Member
May 20, 2008
5,658
22
38
PHP:

(PHP Hypertext Preprocessor) A scripting language used to create dynamic Web pages. With syntax from C, Java and Perl, PHP code is embedded within HTML pages for server side execution. It is commonly used to extract data out of a database and present it on the Web page. NT/2000 and Unix Web servers support the language, and it is widely used with the mSQL database. PHP was originally known as "Personal Home Page." See mSQL.
 

Kreskin

Doctor of Thinkology
Feb 23, 2006
21,155
149
63
The $date is arrived at by other code. I want a series of elseif statements that would bring out part of the condition, that being part of a date. I don't want the year because I don't want to change it every year.



Example: This works but it has the the year: If I take the == out and reduce it = it doesn't work.

<? if ($date==("January 01, 2010"))
echo "<font size=-2>Birthday of J. Edgar Hoover</font>";

I would like it to be something like this , which excludes the ==:

<? if ($date=("January 01"))
echo "<font size=-2>Birthday of J. Edgar Hoover</font>";

However using that makes it appear everyday of the year because every month has one of those letters.

Am I making any sense?

I want the code to deliver me a statement on January 1, based on client-side user input that results in $date being January 1, 2009, or 2010 or 2011 etc.
 

Andem

dev
Mar 24, 2002
5,643
128
63
Larnaka
This should work:

Code:
<?php
$tellmethedate = $_GET["t"];

function daywas($input) {
        if($input == "January 01") {
                $output = "Birthday of J. Edgar Hoover";
        }
        elseif ($input == "January 02") {
                $output = "The day after new years";
        }
        else {
                $output = "This day is nothing special";
        }
        return $output;
}

$result = daywas($tellmethedate);

echo("$result");
?>
I wrote a very quick function which takes the user input and checks it against the days listed.. I just did January 01 and 02.. else it will return "The day is nothing special". Input is collected from file.php?t=January+01.

If you've got a lot of dates, I would suggest using mysql.

Edit: I had not had a coffee yet. Alright I see what you want to do, you've got another bit of code outputting the date in the format of January 01, 2009 and you're trying to get the script to recognise this as just January 01. I see. There is a much simpler way without resorting to using preg_replace (a waste of resources).

Whatever the code is outputting, the php date format should just be changed from date("F d, Y"); to date("F d") so the function above would work the way you wanted it to.

The $date is arrived at by other code. I want a series of elseif statements that would bring out part of the condition, that being part of a date. I don't want the year because I don't want to change it every year.

Example: This works but it has the the year: If I take the == out and reduce it = it doesn't work.

<? if ($date==("January 01, 2010"))
echo "<font size=-2>Birthday of J. Edgar Hoover</font>";

I would like it to be something like this , which excludes the ==:

<? if ($date=("January 01"))
echo "<font size=-2>Birthday of J. Edgar Hoover</font>";

However using that makes it appear everyday of the year because every month has one of those letters.

Am I making any sense?

I want the code to deliver me a statement on January 1, based on client-side user input that results in $date being January 1, 2009, or 2010 or 2011 etc.
 
Last edited:
  • Like
Reactions: Kreskin