... lessons: the basic functions 01: writing in php
You may've seen on some
PHP-sites, that in most functions on the site, they use a command called
echo to give an output to the user in front of his screen.
Writing something in PHP is very simple! Look at this:
This is written in PHP,
but
this is written in HTML.
No cheating upthere ;)...I
wrote the PHP-text in PHP and the HTML-text in HTML. You may have to
know, that you sometimes have to use HTML-scripts in your PHP-writings,
so you have to know a little bit of HTML, before you start on PHP. Now,
the question is: How did I do that, and how can you learn it? Well, I
told we could use the echo-command to write text. As simple, as it is,
I'll here give you an example:
<?php echo "Hi,
I'm something written in PHP!" ?>
And as an output, it will be transformed into this:
Hi, I'm something
written in PHP!
Okay, I may explain the
whole script to you, so you understand. The first part of script is
"<?php", and I hope, you know, that this is the way to start a
PHP-script. If your browser meets this in your HTML-code, it will
automatically be transformed into another part of code, so your
document doesn't contain the whole code in it's text. This next thing,
we now use in the script is the command echo. If you use the
quotation-marks after echo, it will be transformed into a string
and will be written in your document. The "?>" ends the PHP-script
and then the browser continues on doing the HTML-code, until it meets
another script. Simple, huh? Yeah.
As well, you could use the
command called print. print is used in the same way as echo;
just simply put some quotation marks after print, and it will be
transformed into a string, which will be written in your document. Now,
there's a little fact, you'd probably like to know. Instead of using
the "<?php" and "?>", you could simply remove the "php" and use
"<?" and "?>" instead. Also, you could instead of these two use
"<script language="php">" and "</script>", but still, I
prefer "<?php" because of its way to say, that it is a PHP-script,
we're talking 'bout.
Now, I want to make two
sentences in one script. Simply, I do it like this:
<?php
echo "Here's my first line...<br>";
echo "...and here's my second...";
?>
Don't forget that
semicolon! It's very important! It's always used at the end of every
command, you use in PHP. Now, we want it a little easier. I want the two
sentences pushed into one line in the script. Here's where the
semicolon is very important:
<?php
echo "First line"; echo "And second!"
?>
Simple, huh? Way to go!
Clever little you...*pulls your cheek* ^___^ That was ya first
PHP-script! Wanna learn more? Continue to the next step! I mean it!
next
»