Simple Math with PHP

Posted: February 28, 2009

PHP has built-in math functionality for most of your mathematical desires.  Here are a few of the common math operators and what they do:

+      adds numbers
-    subtracts
*    multiplies
/    divides
%    modulus (the remainder of a division)
Read the rest of this entry »

More Fun with PHP Strings

Posted: February 27, 2009

PHP is a pretty good language to work with text.  Some programming languages have separate types for single characters (chars) and strings.  With PHP it’s pretty much all the same.  Some languages (I’m looking at you C!) don’t allow strings at all, and only have characters.  So, with as much as PHP keeps out of your way, strings aren’t that bad. Read the rest of this entry »

PHP Datatypes

Posted: February 24, 2009

Programming languages all support different types of data, such as numbers or text.  But to the programming language, it gets even more specific.  There are many different kinds of numbers, for example, depending on whether it has a decimal or not.

Some common datatypes:
int  – an integer, or whole number without a decimal
float – floating point numbers, basically a number with a decimal
double – same as a float, but more specific.  It can hold longer values and more decimal places
bool – Boolean values.  Basically true or false
string – strings of text
array – a special type of variable which can hold a whole set of other variables inside it. Read the rest of this entry »

Forms + PHP = BFF

Posted: February 20, 2009

One great way to use PHP is to use web forms to get data from visitors to your site. You’re all probably familiar with the standard HTML forms:
<form method=“post” action=“page.php”>
Please enter your name: <input type=“text” name=“username” />
<input type=“submit” value=“Send” />
</form>

See those extra attributes in the form tag, method and action? Those are how you can send things to a PHP script on another page.

Read the rest of this entry »