Jump to content

Skinning a cat (Or how many ways to output "Hello World!")


benanamen

Recommended Posts

We all know in PHP there are many ways to come up with the same exact result. Just for fun, lets see how many ways you can come up with to output the standard Hello World!. I did this on another forum awhile back and there are many. I will start off with the two most basic ways;

 

 

echo "Hello, World!";

 

print "Hello, World!";

 $b=('010010000110010101101100011011000110111100100000010101110110111101110010011011000110010000100001');
     
$split str_split($b8);
 
$txt '';
     for(
$i 0$l count($split); $i $l$i++) {
         
$txt .= chr(bindec($split[$i]));
     }
     echo 
$txt;

This code grabs the text from this forum post. Sort of a recursive implementation. :)

 

$url = 'http://forums.phpfreaks.com/topic/298555-skinning-a-cat-or-how-many-ways-to-output-hello-world/';
$content = file_get_contents($url);
$output = preg_match("#Or how many ways to output ([^\)]*)#", $content, $match);
echo str_replace('"', '', $match[1]);

You'll have to wait for this one. Shuffle really isn't 'random' - it took 245,760 iterations to get the value (every time) on my machine.

$letters = array('H','e','l','l','o',',',' ','W','o','r','l','d','!');
$string = '';
 
while($string != 'Hello, World!') {
    shuffle($letters);
    $string = implode('', $letters); 
}
echo $string;
<?php

$string = '';

$expected = 'Hello, World!';

$biggestChar = 0;

for ($i = 0; $i < strlen($expected); $i++) {
$biggestChar = max($biggestChar, ord($expected[$i]));
}

while ($string != $expected) {
$string = '';

for ($i = 0; $i < strlen($expected); $i++) {
$char = mt_rand(1, $biggestChar);
$string .= chr($char);
}
}

echo $string;
I've been running this for about 30 minutes now with $expected = 'Hello' and it hasn't finished yet.

Archived

This topic is now archived and is closed to further replies.



×
×
  • 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.