benanamen Posted October 12, 2015 Share Posted October 12, 2015 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!"; Link to comment https://forums.phpfreaks.com/topic/298555-skinning-a-cat-or-how-many-ways-to-output-hello-world/ Share on other sites More sharing options...
scootstah Posted October 12, 2015 Share Posted October 12, 2015 Moving to misc. This could get fun. Link to comment https://forums.phpfreaks.com/topic/298555-skinning-a-cat-or-how-many-ways-to-output-hello-world/#findComment-1523059 Share on other sites More sharing options...
Psycho Posted October 12, 2015 Share Posted October 12, 2015 foreach(array(72,101,108,108,111,44,32,87,111,114,108,100,33) as $l) { echo chr($l); } Link to comment https://forums.phpfreaks.com/topic/298555-skinning-a-cat-or-how-many-ways-to-output-hello-world/#findComment-1523068 Share on other sites More sharing options...
ignace Posted October 12, 2015 Share Posted October 12, 2015 file_put_contents('php://output', 'Hello, World!'); Link to comment https://forums.phpfreaks.com/topic/298555-skinning-a-cat-or-how-many-ways-to-output-hello-world/#findComment-1523069 Share on other sites More sharing options...
ignace Posted October 12, 2015 Share Posted October 12, 2015 $tmp = tmpfile(); fwrite($tmp, 'Hello, World!'); readfile(stream_get_meta_data($tmp)['uri']); fclose($tmp); Link to comment https://forums.phpfreaks.com/topic/298555-skinning-a-cat-or-how-many-ways-to-output-hello-world/#findComment-1523071 Share on other sites More sharing options...
benanamen Posted October 12, 2015 Author Share Posted October 12, 2015 echo str_replace("JimL","World","Hello JimL!"); Link to comment https://forums.phpfreaks.com/topic/298555-skinning-a-cat-or-how-many-ways-to-output-hello-world/#findComment-1523074 Share on other sites More sharing options...
benanamen Posted October 12, 2015 Author Share Posted October 12, 2015 echo strrev("!dlroW olleH"); Link to comment https://forums.phpfreaks.com/topic/298555-skinning-a-cat-or-how-many-ways-to-output-hello-world/#findComment-1523075 Share on other sites More sharing options...
benanamen Posted October 12, 2015 Author Share Posted October 12, 2015 echo str_rot13("Uryyb Jbeyq!"); Link to comment https://forums.phpfreaks.com/topic/298555-skinning-a-cat-or-how-many-ways-to-output-hello-world/#findComment-1523076 Share on other sites More sharing options...
benanamen Posted October 12, 2015 Author Share Posted October 12, 2015 echo strtr("Happy Coder!","apyCder","eloWrld"); Link to comment https://forums.phpfreaks.com/topic/298555-skinning-a-cat-or-how-many-ways-to-output-hello-world/#findComment-1523077 Share on other sites More sharing options...
benanamen Posted October 12, 2015 Author Share Posted October 12, 2015 define("CONSTANT", "Hello world."); echo CONSTANT; Link to comment https://forums.phpfreaks.com/topic/298555-skinning-a-cat-or-how-many-ways-to-output-hello-world/#findComment-1523078 Share on other sites More sharing options...
benanamen Posted October 12, 2015 Author Share Posted October 12, 2015 $helloworld = 'Hello World!'; printf('%s', $helloworld); Link to comment https://forums.phpfreaks.com/topic/298555-skinning-a-cat-or-how-many-ways-to-output-hello-world/#findComment-1523079 Share on other sites More sharing options...
benanamen Posted October 12, 2015 Author Share Posted October 12, 2015 $helloworld = 'Hello World!'; $helloworld = sprintf('%s', $helloworld); echo $helloworld; Link to comment https://forums.phpfreaks.com/topic/298555-skinning-a-cat-or-how-many-ways-to-output-hello-world/#findComment-1523080 Share on other sites More sharing options...
benanamen Posted October 12, 2015 Author Share Posted October 12, 2015 $hex = '48 65 6c 6c 6f 20 57 6f 72 6c 64'; foreach (explode(' ', $hex) as $bit) { echo chr(hexdec($bit)); } Link to comment https://forums.phpfreaks.com/topic/298555-skinning-a-cat-or-how-many-ways-to-output-hello-world/#findComment-1523081 Share on other sites More sharing options...
benanamen Posted October 12, 2015 Author Share Posted October 12, 2015 $test = "Hello World!"; var_export($test); Link to comment https://forums.phpfreaks.com/topic/298555-skinning-a-cat-or-how-many-ways-to-output-hello-world/#findComment-1523082 Share on other sites More sharing options...
benanamen Posted October 12, 2015 Author Share Posted October 12, 2015 echo base64_decode('SGVsbG8gV29ybGQ='); Link to comment https://forums.phpfreaks.com/topic/298555-skinning-a-cat-or-how-many-ways-to-output-hello-world/#findComment-1523083 Share on other sites More sharing options...
benanamen Posted October 12, 2015 Author Share Posted October 12, 2015 echo hex2bin("48656c6c6f20776f726c6421"); Link to comment https://forums.phpfreaks.com/topic/298555-skinning-a-cat-or-how-many-ways-to-output-hello-world/#findComment-1523084 Share on other sites More sharing options...
benanamen Posted October 12, 2015 Author Share Posted October 12, 2015 foreach (range('d', 'w') as $v) { $a[] = $v; } echo ucwords("$a[4]$a[1]$a[8]$a[8]$a[11] $a[19]$a[11]$a[14]$a[8]$a[0]!"); Link to comment https://forums.phpfreaks.com/topic/298555-skinning-a-cat-or-how-many-ways-to-output-hello-world/#findComment-1523085 Share on other sites More sharing options...
benanamen Posted October 12, 2015 Author Share Posted October 12, 2015 echo <<<EOT Hello World! EOT; Link to comment https://forums.phpfreaks.com/topic/298555-skinning-a-cat-or-how-many-ways-to-output-hello-world/#findComment-1523086 Share on other sites More sharing options...
benanamen Posted October 12, 2015 Author Share Posted October 12, 2015 foreach (explode(' ', '72 101 108 108 111 32 87 111 114 108 100') as $bit) { echo chr($bit); Link to comment https://forums.phpfreaks.com/topic/298555-skinning-a-cat-or-how-many-ways-to-output-hello-world/#findComment-1523087 Share on other sites More sharing options...
benanamen Posted October 12, 2015 Author Share Posted October 12, 2015 $a = range('d', 'w'); echo ucwords("$a[4]$a[1]$a[8]$a[8]$a[11] $a[19]$a[11]$a[14]$a[8]$a[0]!"); Link to comment https://forums.phpfreaks.com/topic/298555-skinning-a-cat-or-how-many-ways-to-output-hello-world/#findComment-1523088 Share on other sites More sharing options...
benanamen Posted October 12, 2015 Author Share Posted October 12, 2015 $b=('010010000110010101101100011011000110111100100000010101110110111101110010011011000110010000100001'); $split = str_split($b, 8); $txt = ''; for($i = 0, $l = count($split); $i < $l; $i++) { $txt .= chr(bindec($split[$i])); } echo $txt; Link to comment https://forums.phpfreaks.com/topic/298555-skinning-a-cat-or-how-many-ways-to-output-hello-world/#findComment-1523089 Share on other sites More sharing options...
benanamen Posted October 12, 2015 Author Share Posted October 12, 2015 $_="\x70\162\151\x6e\164\x5f\162";$__="\145\170\x65\x63";$___="\x65\143\150\x6f";$____="\110\x65\154\x6c\x6f\040\127\x6f\x72\x6c\144\047"; $_($__("$___ '$____")); Link to comment https://forums.phpfreaks.com/topic/298555-skinning-a-cat-or-how-many-ways-to-output-hello-world/#findComment-1523090 Share on other sites More sharing options...
Psycho Posted October 12, 2015 Share Posted October 12, 2015 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]); Link to comment https://forums.phpfreaks.com/topic/298555-skinning-a-cat-or-how-many-ways-to-output-hello-world/#findComment-1523094 Share on other sites More sharing options...
Psycho Posted October 12, 2015 Share Posted October 12, 2015 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; Link to comment https://forums.phpfreaks.com/topic/298555-skinning-a-cat-or-how-many-ways-to-output-hello-world/#findComment-1523097 Share on other sites More sharing options...
scootstah Posted October 12, 2015 Share Posted October 12, 2015 <?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. Link to comment https://forums.phpfreaks.com/topic/298555-skinning-a-cat-or-how-many-ways-to-output-hello-world/#findComment-1523107 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.