Error » Certification & Programming center Error !! » Programming tutorials » Where to Start with PHP Programming

Programming tutorials All Knowledge Info and links to posted here

Post New Thread Reply
  Where to Start with PHP Programming
LinkBack Thread Tools Display Modes
Old 27-Feb-2007, 12:58 AM   #1 (permalink)
Fixed Error!
 
AQUARIAN's Avatar

Posts: 803
Join Date: Feb 2007
Rep Power: 2 AQUARIAN is on a distinguished road

IM:
Default Where to Start with PHP Programming

Where to Start with PHP Programming


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
  1. In Code Documentation
    As I’ve mentioned above, get in the habit of writing plain text explainations for what you’re doing in the code you’re designing. It’s not difficult to put in a bit of text before a segment of code to explain what you’re going to be doing.
  2. Clear and Appropriate Variable Names
    While coding, you’re most likely going to be declaring variables. (Variables are like boxes of information stored in memory) The more clearly you name your variables, the better off you’ll be later, and the less likely you are to run into conflicts or confusion.
Some Examples

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
AQUARIAN is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
   


   
Post New Thread Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -8. The time now is 10:25 AM.

Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0

DMCA Policy

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228