Chapter 6: Writing and Editing |
|
Text editors |
|
WARNING: Text editors are not the same as word processors;know the difference. A text editor such as NotePad won't put invisible or non-printing characters in the file. Exception: sometimes another text editor may display a ^M whenever there was a carriage return in the file created by NotePad. This generally has no real effect, as long as you remember to always upload in ASCII. On the other hand, a word processor such as MS-Word or Word Perfect will put all sorts of strange stuff in the file. It's supposed to do that; they are special characters that don't display but are used to control the way a document looks on screen and on paper. These special characters will wreak havoc on a script. It's just not possible to create a properly functioning script with a word processor. Don't even think of using one. |
|
|
There are plenty of free or inexpensive text editors available. If you don't like the ones that come with Windows, or whatever OS you're using, feel free to use something else. My personal favorite is a Windows program called EditPlus. It's a shareware program, so you can download it and try it out before you pay for it. Get it here -> http://www.editplus.com/.Check out all the features this one has and you'll wonder how you survived without it. |
How can I learn to write PHP scripts? |
The best way is probably to learn by example. Read other scripts and see how they work. A good PHP reference book is a big help. Once you begin to see how PHP scripts work, you can write your own. Code them from start to finish or by combining parts of existing scripts to create new ones. This book will give you several ready-to-run scripts and a number of functions you can use to build more complex scripts. You'll see a complete script in just a moment. |
PHP notation |
Blocks of PHP code begin with <?php and end with ?> This works the same way as the <SCRIPT> and </SCRIPT> tags identify a block of JavaScript code on an HTML page. It tells the web server that everything between the tags is PHP code. If your file is all PHP, you'll only need one set of these tags. That's not always the case, though. Sometimes you want to mix in some HTML code in the same file. The web server will follow the instructions in every PHP block it finds, whenever and wherever it finds it. Any HTML code in the file will be sent to the browser. If a PHP block causes some HTML code to be created, that HTML will be sent to the browser, too. But - and this is important to remember - the browser's View->Source feature will only show the HTML output. The PHP code remains hidden. |
|
|
Operators and Identifiers |
Operators are the symbols that perform some action. They include math operators for addition(+), subtraction(-), multiplication(*) and division(/). Identifiers are names for functions and variables. Computers use these names to refer to where things are in memory. Identifiers can be be made up of as many letters, numbers and underscores as you want but the first character cannot be a number. In addition, they are case-sensitive. So ... this_identifier and this_IDENTIFIER will be treated as two different identifiers in your script. A function is a block of code that does one specific job, such as sending an email message, finding and displaying the current date or writing some information into a file. PHP has a boatload of built-in functions for various little jobs. You can often just call on a built-in function instead of having to write your own. You call a function by typing in its name, followed by a set of parentheses, like this: my_function(); If you need to give the function some variables to use, you put their names in the parentheses, like this: my_function($variable_1, $variable_2); A variable is an identifier for an item of data or a list of data items. Every variable in PHP is preceded by $; this tells the computer that it's a variable. Each variable has a "Data Type" and some value or list of values. There are 3 data types: Here are a couple of really cool things to remember about variables. One, you don't have to tell the program what data type will be stored in a variable; it will just use the type that matches whatever data you stored in the variable. Two, you can make it pretend to be another data type by using the settype function. |
| Previous Page Table of Contents Next Page |
Copyright © 2004 Steve Humphrey |