| Welcome to New Nsider. We hope you enjoy your visit. You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free. Join our community! If you're already a member please log in to your account to access all of our features: |
| PHP - Lesson 1; Introduction to PHP | |
|---|---|
| Tweet Topic Started: Jul 15 2006, 02:57 PM (736 Views) | |
| Cube | Jul 15 2006, 02:57 PM Post #1 |
|
White Pikmin
|
It is adviseable to know HTML before even attempting this lesson...web space can also be helpful. Anyway, onto the basics... The File: PHP documents should end with a php file extension, otherwise the code will not be processed. For example... File: test.php ...is valid. Now, let's move onto the php tags. Start and End Tags: For all php code, it must be within the following tags...
"//code here" is a comment, and therefore, not parsed by the php engine. There are other tags it can be put into, but it's best to keep it within those. PHP Comments: What is a comment? Well, it's just that...a comment, usualy to make the code more understandable. Comments are not parsed by the engine, and effect nothing. Single Line Comment... //This is a line, commented. Change text as desired Secondary Single Line Comment... #This is as well, a commented line. Block Comment... /* Look! This is all commented, this is a block, which can be as long as you want it to be! */ The echo statement, and print() function: The echo statement is used to output data, the print function does the same, but is, a function. Echo statement...
Print function...
Characters, are known as strings, and must always be enclosed in quotation marks (this is not the same for other datatypes), single (') or double ("). As well, statement and functions should usualy end with a semicolon (;), most of the time, you'll find this will result in a parse error should you not follow these rules. HTML with...PHP?: Now, let's work with combining HTML and PHP, there are a few ways to do this, but we'll go over the easiest.
As you can see, HTML is not contained in the PHP tags. But PHP is indeed included in this code. Escaping Certain Characters: Sometimes, you need to escape characters, for example...
That will give you a parse error, so you need to escape them with a backslash (\)
Well, this concludes lesson 1, I'll post another today if I have time... Lesson Assignments: -Post the code you would use to echo "Hello World!" (with quotes, not using single quotes) in this thread. -Then, add a comment to what the code does. -Put it in the body of an HTML document. -Post it. Members who've completed this lesson: Phantom123, B [Missing PHP Comment] Speedy, A Zero the Warrior, A _Waffelz has turned off the smiley code for Cubert, so smileys don't go where they aren't supposed to_ |
| |
![]() |
|
| Cube | Jul 15 2006, 03:06 PM Post #2 |
|
White Pikmin
|
And on another note...everyone is allowed to post. >_> |
| |
![]() |
|
| Ganondorf10101 | Jul 15 2006, 03:25 PM Post #3 |
![]()
Rebel Trooper
|
Pfft, PHP. I'm going to do some hardcore scripting in a few years. *cries* |
![]() - Sig Redesigned by Ganondorf10101, Credit goes to arcHITect of NIC - Ganon10101 | |
![]() |
|
| SpeedyZ1 | Jul 15 2006, 03:45 PM Post #4 |
![]()
White Pikmin
|
Edit: I'll edit this post soon. |
![]() |
|
| Cube | Jul 15 2006, 04:00 PM Post #5 |
|
White Pikmin
|
Lesson assignments are up, at the bottom of the first post. |
| |
![]() |
|
| Phantom123 | Jul 15 2006, 04:17 PM Post #6 |
|
Covenant Elite
|
What it does is, in the background, at the top of the page, it rights the text I mentioned. --- This space will be used for the Other half of the assignment
This combines PHP and HTML. It makes the basic Text-design of a Page. |
|
<img src=http://pic.piczo.com/img/i15885113_21172_2.gif> Best. Objection. Ever. | |
![]() |
|
| Cube | Jul 16 2006, 09:58 AM Post #7 |
|
White Pikmin
|
Ok, Phantom, you've completed Lesson 1. |
| |
![]() |
|
| Deleted User | Jul 16 2006, 10:45 AM Post #8 |
|
Deleted User
|
._. I don't get any of this. I think you need to explain what stuff means a little more... |
|
|
| Phantom123 | Jul 16 2006, 10:52 AM Post #9 |
|
Covenant Elite
|
He explains it plenty. He just puts too much>-< |
|
<img src=http://pic.piczo.com/img/i15885113_21172_2.gif> Best. Objection. Ever. | |
![]() |
|
| Cube | Jul 16 2006, 10:53 AM Post #10 |
|
White Pikmin
|
Eh...here is a possibly more understandable version... <?php // Code goes here ?> Now, <?php and ?> tell that it needs to be parsed (processed) as php. Therefore, any php code should go inside there. "// Code goes here" is a comment, the double slashes makes it that. The echo statement, and print functions, aren't hard to use. They just require an argument to be useful. For example... <?php echo "this is where a string would go"; ?> A string, is what you usualy type in a post, letters, words, whatever. The double quotes (or single quotes) make it known that it's a string. That can be changed, but that's in lessons 2. The print() function, is nearly the same, but it's like this... <?php print("Look, another string"); ?> The semicolon, says that's the end of the function, process, or whatever. Now, because the quotes/single quotes are what contains a string, it's wise to escape them if you want them displayed as text. So, if you want "Hello World!" to display in an echo statement, you'd do this... <?php echo "\"Hello World!\""; ?> The backslash escapes 2 of the quotes, as you can see. |
| |
![]() |
|
| Go to Next Page | |
| « Previous Topic · Archive · Next Topic » |
| Theme: Ashyn | Track Topic · E-mail Topic |
4:04 PM Jul 10
|









4:04 PM Jul 10