Yes, I know, easy code. Well, this is just to show some users how easy php is. Without further ado, the code itself:
Explanation:Code:<?php echo "Hello World!"; ?>
<?php - tells the file that this is php coding. *.php files can contain html by default. The php extention says this is where I want the php to go. You can have multiple php coding in a file.
echo "Hello World!"; - Prints "Hello World" to the screen(without the quotes). When you want to output text or anything that is not a variable or such, wrap it in quotes so php doesnt interpret it as such.
?> - Closes the php code.
Echo is actually a function in PHP you can use it like:
I think that is the proper way of doing it - I suppose deep down everything is made up of functions and variables - then computer language - 0's and 1's - somewhat depressing...Code:echo("Hello World!");
Both ways work thou.
@kahotic : You have to crawl before you walk. I am sure some one who has never used PHP before will find it helpful
Actually, it isn't a function:
PHP: echo - Manualecho() is not actually a function (it is a language construct), so you are not required to use parentheses with it
Well then - I'm an idiot.
You can still use it like a function however =)
lol, I wouldn't go that far. You showed an alternative method to use it which some people may prefer (like yourself).
Yeh, I remember when I was first learning php(couple years back when I was 11 or so), it said that using parentheses is the correct way of using it. I find it better to just use 'echo' as a keyword rather than "function".
I've never read that parentheses is the correct way to use it. In fact, in some situations, you can't use parentheses (IE: You are passing multiple parameters to it).
Im pretty sure you can pass multiple params to it if you use the ():
I am pretty sure all those would work just like regular functions. (but its not a function lols)Code:<?PHP
$var1 ="hello";
$var2 = "world";
echo("hello ".$var2);
echo($var1." ".$var2);
echo("hello"." "."world");
?>
Technically, wouldn't the concatenation happen first, resulting in a single parameter?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks