Just for fun...

In PHP there are many ways to do the same thing. (Perhaps not such a good idea…). For fun, I would like to see how many ways we can come up with to output the basic Hello World phrase. I am guessing we could come up with at least a hundred. I will start with the two most obvious ones and contribute more when the list gets going.

1.[php]<?php
echo “Hello World”;
?>[/php]

2.[php]<?php
print “Hello World”;
?>[/php]

[php]<?php

$hex = ‘48 65 6c 6c 6f 20 57 6f 72 6c 64’;
foreach (explode(’ ', $hex) as $bit) {
echo chr(hexdec($bit));
}[/php]

[php]<?php
$test = “Hello World”;
var_export($test);
?>[/php]

[php]<?php
echo base64_decode(‘SGVsbG8gV29ybGQ=’);
?>[/php]

[php]echo hex2bin(“48656c6c6f20776f726c6421”);[/php]

[php]<?php
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]!");
?>[/php]

[php]<?php
echo <<<EOD
Hello World
EOD;[/php]

the obvious one…

[php]<?php
?>
Hello World[/php]

[php]<?php
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]!");
[/php]

[member=71845]JimL[/member] , I messed it up when I pasted in the ucwords update.

[php]<?php
foreach (explode(’ ', ‘72 101 108 108 111 32 87 111 114 108 100’) as $bit) {
echo chr($bit);
}[/php]

[member=46186]Kevin Rubio[/member] still, the loop is unnecessary

[php]<?php
$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]!");[/php]

[member=71845]JimL[/member] , Good one, yet still another way to do it.

[php]<?php
$b=(‘010010000110010101101100011011000110111100100000010101110110111101110010011011000110010000100001’);
$split = str_split($b, 8);
$txt = ‘’;
for($i = 0, $l = count($split); $i < $l; $i++) {
$txt .= chr(bindec($split[$i]));
}
echo $txt;
?>[/php]

[php]<?php
$="\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";
$
($("$
'$
__"));[/php]

[php]<?php
echo str_replace(“JimL”,“World”,“Hello JimL!”);
?>[/php]

[php]<?php
echo strrev("!dlroW olleH");
?>[/php]

[php]echo str_rot13(“Uryyb Jbeyq!”);[/php]

[php]echo strtr(“Happy Coder!”,“apyCder”,“eloWrld”);[/php]

[php]
define(“CONSTANT”, “Hello world.”);
echo CONSTANT;
[/php]

;D

Sponsor our Newsletter | Privacy Policy | Terms of Service