![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
![]() |

|
| Programming tutorials All Knowledge Info and links to posted here |
![]() |
|
Where to Start with PHP Programming
|
LinkBack | Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Fixed Error!
Posts: 803
Join Date: Feb 2007
Rep Power: 2
IM:
|
I’m going to start this tutorial with an assumption. I’m going to assume that you, the reader, already have access to a PHP enabled server. My specialization is programming, not server setup, so I’ll leave that part out of this. If for some reason, you DON’T yet have access to a PHP enabled server, or you are wanting to install your own, there are a lot of great resources out there which can help you through that process. First off, a little discussion about the nature of PHP. PHP is a server side scripting language, which means that it runs stuff on the server, and returns the results of that process to the web browser of the person who ran it. Example: When somone on a website clicks “Submit” on a contact form, the server receives the data but doesn’t inherently know what to do with that data. This is where PHP comes in. If the data is submitted to a PHP script on the server, that script can then take that data and email it to someone or stick it in a database.A PHP script can be as simple as a single line of code to do a math calculation, or complex enough to run an entire website. The format of PHP code is similar to C but in my opinion, is much more forgiving. A Little About Style One of the most important lessons to be learned by any coder, even before you really get into much of it, is code documentation. In my opinion, one of the worse problem with many coders is that they don’t know how to document their code. This will be a pain both to you when you want to go back and edit something, and to anyone else who needs to use your code. I can’t say this strongly enough. LEARN TO DOCUMENT ALL YOUR CODE! I’m not talking so much about pages of documentation in addition to the script you are writing. Rather, I’m talking about writing out in the code itself, what you’re doing with each statement or set of statements. You will appreciate it in the future, when you come back to a script and want to figure out what it does, and other programmers who may use your work, will also bless you. It’s also a pretty key factor in getting hired in this industry. If an employer knows what they’re doing, they’re going to have someone look through your code to make sure it’s well formed and not going to cause their other programmers headaches. Keys to Good Style
Well, let’s take a look at some PHP Code now so we get the feel for what we’re looking at. A standard PHP script will be enclosed in tags like this: <?PHP # Some php commands here ?> There are some variations of this as well. For example, some servers will allow you to simply use <? instead of <?PHP. Usually though, it’s good form to use the full <?PHP for clarity. Now, let’s take a look at some examples of good code documentation and bad code documentation. Poor Code Style: <? $x="Some text"; $y="some more text"; $z=$x.$y; echo "Combined text variables = ".$z ; ?> Better Code Style: <?PHP # Declare some text variables $text_1 = "Some text "; $text_2 = "some more text"; # Combine the two previous variables into a third variable $text_combined = $text_1 . $text_2; # Print out the results echo "Combined text variables = " . $text_combined; ?> Output: Combined text variables = Some text some more text Both of these examples would print out the same result to the browser, but you’ll notice that in the second example, I’ve added line breaks in appropriate places, used more appropriate variable names, and have added comments before each segment of code. (comments are denoted in PHP by a # sign at the beginning of a line) You could even go so far as to add comments to the very beginning of the script, explaining when it was made and what it’s purpose was. See this example… Better Code Style: <?PHP # Sample PHP Programming Script # Designed Nov. 18, 2005 # Used on "Where to Start PHP Programming" as an example of good # programming style. # Declare some text variables $text_1 = "Some text "; $text_2 = "some more text"; # Combine the two previous variables into a third variable $text_combined = $text_1 . $text_2; # Print out the results echo "Combined text variables = " . $text_combined; ?> So what do you think? Still want to be a PHP Programmer? I hope so… It can be a lot of fun. In the next few tutorials we’ll start going over some of the basic programming structures and commands that you’ll be using as you start coding. You may also find it useful to get a book like the one I’ve recommended at the top of this page. These tutorials will give you the basics and help you to get started, but if you want to get into more complex coding, a book like this one is the way to go. Source :WarkenSoft Productions |
|
|
|
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|