Friday, May 18, 2007

Exploring PHP

I finished working through the simple PHP tutorial today. It was pretty helpful. Here are my notes:

Hint: "It's not working!?! Why?!?"
  • Check: Is Apache turned on? duh...
php tag:
  • <?php to start a php tag
  • ?> to end the tag
  • Use the tag within an html file to jump in and out of php.
  • Can jump in and out of php/html within a php block even.
Variable info:
  • Variables always start with a '$'.
  • Can see all reserved variables through phpinfo().
  • Variables can be pretty much the same types (bool, int, string, etc.) that they could be in C++, but you don't need to declare them that way. Also some mixed types and type casting is allowed.
Helpful functions:
  • strpos($haystack, 'needle'); //finds the string needle within the variable haystack. Returns the position, or FALSE.
  • int count (mixed $var [, int $mode] ); //Returns the number of elements in var, which is typically an array, since anything else will have one element.
  • PHP can access html form info easily. See tutorial for help.
Things to explore:
  • It seems like you can use php alone as well, without html surrounding it. Is that true?
    • For instance, <?php phpinfo(); ?> works fine in its own file.
  • What is "Model View Controller"? It sounds like a way of organizing your code to make it more readable and understandable.
  • The PHP manual is pretty helpful and has a lot of examples and documentation for functions, global variables, etc. I'm impressed with how easy it is to understand.

No comments: