Fun with PHP, join me!

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

User avatar
HungryMind
Forum Commoner
Posts: 41
Joined: Fri Jun 20, 2003 10:33 am
Location: Alameda, CA

Fun with PHP, join me!

Post by HungryMind »

Hello everyone. I may be relatively new to PHP, but that doesn't mean that I can't still have some fun with it. My goal is to make the following script more and more complex as people from the community keep adding to it more and more without changing the actual output. Since I am a "newb," I will start off with something simple, but hopefully you guys can elaborate on what I have done. Let's see what you guys can do!

Code: Select all

<html><head><title>Complex Hello World</title></head>
<body>

<?php
// Help create the most complicated "Hello World" Application in the history of PHP!

define("THE_FIRST_WORD", "Hello");
$the_second_word = "World";

print THE_FIRST_WORD . " " . $the_second_word . "!";
?>

</body>
</html>
Output (obviously):

Hello World!
User avatar
m@ndio
Forum Regular
Posts: 163
Joined: Fri Jun 06, 2003 12:09 pm
Location: UK

Post by m@ndio »

not a very appropriate post mate :wink:
User avatar
HungryMind
Forum Commoner
Posts: 41
Joined: Fri Jun 20, 2003 10:33 am
Location: Alameda, CA

Post by HungryMind »

How so?
User avatar
m@ndio
Forum Regular
Posts: 163
Joined: Fri Jun 06, 2003 12:09 pm
Location: UK

Post by m@ndio »

This forum is for people with problems, I just feel it belongs in the "misc" category. But hey! knock yourself out. I think people share my opinon on this, hence probably why you have had no response...

tar
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

ah, php tennis. We had this before, e.g.
viewtopic.php?t=1668
viewtopic.php?t=1725
why not? But "General Discussion" is probably more appropriate ;)

Code: Select all

<html><head><title>Complex Hello World</title></head>
<body>

<?php
// Help create the most complicated "Hello World" Application in the history of PHP!

define("THE_FIRST_WORD", "Hello");
$the_second_word = "Worl" . chr(100);

print THE_FIRST_WORD . " " . $the_second_word . "!";
?>

</body>
</html>
User avatar
cactus
Forum Regular
Posts: 343
Joined: Tue Jun 10, 2003 4:16 am
Location: UK

Post by cactus »

Well, if I must ;)

Code: Select all

<html><head><title>Complex Hello World</title></head>
<body>

<?php
// Help create the most complicated "Hello World" Application in the history of PHP!

define("THE_FIRST_WORD", "Hello");
$the_second_word = "Worl" . base64_encode(chr(100));

print THE_FIRST_WORD . " " . substr($the_second_word, 0, 4) . base64_decode(substr($the_second_word, 4)). "!";
?>

</body>
</html>
:D

Regards,
User avatar
HungryMind
Forum Commoner
Posts: 41
Joined: Fri Jun 20, 2003 10:33 am
Location: Alameda, CA

Post by HungryMind »

Cool stuff. I understand what you mean now. Maybe this can be moved into another section. Still, however, let's see how far we can take this!!!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

<?php header('Content-type: text/html'); ?>
<html><head><title>Complex Hello World</title></head>
<body>

<?php
// Help create the most complicated "Hello World" Application in the history of PHP!

define("THE_FIRST_WORD", "Hello");
$the_second_word = "Worl" . base64_encode(chr(100));

print THE_FIRST_WORD . " " . substr($the_second_word, 0, 4) . base64_decode(substr($the_second_word, 4)). "!";
?>

</body>
</html>
User avatar
HungryMind
Forum Commoner
Posts: 41
Joined: Fri Jun 20, 2003 10:33 am
Location: Alameda, CA

Post by HungryMind »

Fun, fun, fun.

Code: Select all

<?php header('Content-type: text/html'); ?>
<html><head><title>Complex Hello World</title></head>
<body>

<?php
// Help create the most complicated "Hello World" Application in the history of PHP!

$the_letter_h = "H";
define("THE_FIRST_WORD", "ello");
$the_second_word = "Worl" . base64_encode(chr(100));

for ($the_h_counter = 0; $the_h_counter < 1; $the_h_counter++)
{
        print $the_letter_h;
}

print THE_FIRST_WORD . " " . substr($the_second_word, 0, 4) . base64_decode(substr($the_second_word, 4)). "!";
?>

</body>
</html>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

<?php header('Content-type: text/html'); ?>
<html><head><title>Complex Hello World</title></head>
<body>

<?php
// Help create the most complicated "Hello World" Application in the history of PHP!

$the_letter_h = "H";
define("THE_FIRST_WORD", "ello");

function getTHE_FIRST_WORD()
{
	return THE_FIRST_WORD;
}

$the_second_word = "Worl" . base64_encode(chr(100));

for ($the_h_counter = 0; $the_h_counter < 1; $the_h_counter++)
{
	print $the_letter_h;
}

print getTHE_FIRST_WORD() . " " . substr($the_second_word, 0, 4) . base64_decode(substr($the_second_word, 4)). "!";
?>

</body>
</html>
Judas
Forum Commoner
Posts: 67
Joined: Tue Jun 10, 2003 3:34 pm
Location: Netherlands

Post by Judas »

LOL
O boy i can be real complex!
User avatar
cactus
Forum Regular
Posts: 343
Joined: Tue Jun 10, 2003 4:16 am
Location: UK

Post by cactus »

Code: Select all

<?php 
	header('Content-type: text/html');
	header("Cache-Control: "no-cache, must-revalidate"");
	header("Pragma: "no-cache"");
	header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
	header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
?> 
<html><head><title>Complex Hello World</title></head> 
<body> 

<?php 
// Help create the most complicated "Hello World" Application in the history of PHP! 

$the_letter_h = "H"; 
define("THE_FIRST_WORD", "ello"); 

function getTHE_FIRST_WORD() 
{ 
   return THE_FIRST_WORD; 
} 

$the_second_word = bin2hex("W"). "orl" . base64_encode(chr(100)); 

for ($the_h_counter = 0; $the_h_counter < 1; $the_h_counter++) 
{ 
   print $the_letter_h; 
} 

print getTHE_FIRST_WORD() . " " . chr(hexdec(substr($the_second_word, 0, 2))) . substr($the_second_word, 2, 3) . base64_decode(substr($the_second_word, 5)). "!";
?> 

</body> 
</html>
Regards,

[edit: BTW, are we having a limit on the number additions per post ?]
User avatar
HungryMind
Forum Commoner
Posts: 41
Joined: Fri Jun 20, 2003 10:33 am
Location: Alameda, CA

Post by HungryMind »

cactus wrote:BTW, are we having a limit on the number additions per post ?
Nope, no limit at all.

EDIT:

Code: Select all

<?php
   header('Content-type: text/html');
   header("Cache-Control: "no-cache, must-revalidate"");
   header("Pragma: "no-cache"");
   header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
   header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
?>
<html><head><title>Complex Hello World</title></head>
<body>

<?php
// Help create the most complicated "Hello World" Application in the history of PHP!

$the_letter_h = "H";
$thefinalhoorah = "put the exclamation mark here";
define("THE_FIRST_WORD", "ello");

function getTHE_FIRST_WORD()
{
   return THE_FIRST_WORD;
}

$the_second_word = bin2hex("W"). "orl" . base64_encode(chr(100));

for ($the_h_counter = 0; $the_h_counter < 1; $the_h_counter++)
{
   print $the_letter_h;
}

print getTHE_FIRST_WORD() . " " . chr(hexdec(substr($the_second_word, 0, 2))) . substr($the_second_word, 2, 3) . base64_decode(substr($the_second_word, 5));

switch ($thefinalhoorah)
{
        case "put the exclamation mark here":
                echo "!";
                break;
}

?>

</body>
</html>
A nice switch statement. :D
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Code: Select all

<?php 
header('Content-type: text/html');
header("Cache-Control: "no-cache, must-revalidate"");
header("Pragma: "no-cache"");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("X-PROGRAM-TYPE: HELO-WORLD");

class Person
{
	var $_name;
	var $_talking_to;
	var $_listening_to;
	
	function Person ( $name )
	{
		$this->setName($name);
	}

	function getName ()
	{
		return $this->_name;
	}
	
	function setName ( $name )
	{
		$this->_name = $name;
	}
	
	function talkTo ( &$person )
	{
		$this->_talking_to =& $person;
		$this->_listening_to =& $person;
		$this->_talking_to->listenTo($this);
		$this->say("HELO ".$this->_talking_to->getName());
	}
	
	function say ( $string )
	{
		$this->_talking_to->hear($string);
	}
	
	function listenTo ( &$person )
	{
		$this->_listening_to =& $person;
	}
	
	function hear ( $string )
	{
		echo $string, "\n";
	}
}

?> 
<html><head><title>Complex Hello World</title></head><body> 
<?php 
$jason = new Person('Jason');
$world = new Person('World');
$jason->talkTo($world);
$world->talkTo($jason);
?> 
</body></html>
Could have gone much further... but not yet.
User avatar
HungryMind
Forum Commoner
Posts: 41
Joined: Fri Jun 20, 2003 10:33 am
Location: Alameda, CA

Post by HungryMind »

Very impressive code, but the output is:

HELO World HELO Jason

In order to get "Hello World!", wouldn't your code have to be:

Code: Select all

<?php
header('Content-type: text/html');
header("Cache-Control: "no-cache, must-revalidate"");
header("Pragma: "no-cache"");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("X-PROGRAM-TYPE: HELO-WORLD");

class Person
{
   var $_name;
   var $_talking_to;
   var $_listening_to;

   function Person ( $name )
   {
      $this->setName($name);
   }

   function getName ()
   {
      return $this->_name;
   }

   function setName ( $name )
   {
      $this->_name = $name;
   }

   function talkTo ( &$person )
   {
      $this->_talking_to =& $person;
      $this->_listening_to =& $person;
      $this->_talking_to->listenTo($this);
      $this->say("Hello ".$this->_talking_to->getName());
   }

   function say ( $string )
   {
      $this->_talking_to->hear($string);
   }

   function listenTo ( &$person )
   {
      $this->_listening_to =& $person;
   }

   function hear ( $string )
   {
      echo $string, "\n";
   }
}

?>
<html><head><title>Complex Hello World</title></head><body>
<?php
$jason = new Person('Jason');
$world = new Person('World!');
$jason->talkTo($world);
?>
</body></html>
Post Reply