Page 1 of 3

Fun with PHP, join me!

Posted: Sat Jun 21, 2003 4:39 pm
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!

Posted: Sun Jun 22, 2003 3:36 pm
by m@ndio
not a very appropriate post mate :wink:

Posted: Sun Jun 22, 2003 3:37 pm
by HungryMind
How so?

Posted: Sun Jun 22, 2003 4:10 pm
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

Posted: Sun Jun 22, 2003 4:43 pm
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>

Posted: Sun Jun 22, 2003 4:55 pm
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,

Posted: Sun Jun 22, 2003 9:48 pm
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!!!

Posted: Mon Jun 23, 2003 1:15 am
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>

Posted: Mon Jun 23, 2003 1:51 am
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>

Posted: Mon Jun 23, 2003 2:31 am
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>

Posted: Mon Jun 23, 2003 6:02 am
by Judas
LOL
O boy i can be real complex!

Posted: Mon Jun 23, 2003 6:19 am
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 ?]

Posted: Mon Jun 23, 2003 10:41 am
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

Posted: Mon Jun 23, 2003 1:06 pm
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.

Posted: Mon Jun 23, 2003 1:14 pm
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>