An Introduction to PHP
PHP is a widely used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. This blog post is an attempt to give an overview of the PHP language and it’s various features. This blog post assumes that you already have a web server (eg: apache) and PHP installed on your box. You can also use some easy to install Apache distributions containing MySQL and PHP such as XAMPP and MAMP.
So let’s get started!
The default delimiter syntax (recommended) opens with
<?php and concludes with
?>, like this:
<?php echo "Hello World!!"; ?>
The other alternative syntax requires enabling PHP’s
short_open_tag directive, like this:
<? print "Hello World!!"; ?>
When short-tags syntax is enabled and you want to quickly escape to and from PHP to output a bit of dynamic text, you can omit these statements using an output variation known as short-circuit syntax:
You can also use the
<script> tags to delimit PHP code
<script language="php"> print "Hello World!!"; </script>
The last syntax uses ASP style delimiters, however this style syntax has been removed as of PHP 6. See the example below
<% print "Hello World!!."; %>
Data Types in PHP
The following are the different data types available in PHP…
In PHP, you can use zero to represent FALSE, and any nonzero value to represent TRUE. A few examples follow:
$isTrue = false; // false. $isTrue = 1; // true. $isTrue = -1; // true. $isTrue = 5; // true. $isTrue = 0; // false.
An integer is quite simply a whole number, or one that does not contain fractional parts. Decimal (base 10), octal (base 8), and hexadecimal (base 16) numbers all fall under this category. Examples are 50, -20, 0755(octal)
The maximum supported integer size is platform-dependent, although it is typically positive or negative 2^31. If you attempt to surpass this limit within a PHP script, the number will be automatically converted to a float.
Floating-point numbers allow you to specify numbers that contain fractional parts. Examples are:
A string is any series of characters enclosed in ‘single’ or “double quotes”. An example is:
$color = "maroon";
You could retrieve a particular character of the string by treating the string as an array, like this:
$parser = $color; // Assigns 'r' to $parser since 'r' is at position 2 [m(0) a(1) r(2)] in the array above.
Compound Data Types
Arrays are one of the most powerful data types available in PHP, due to their ability to map information using key to value pairing. Example:
$state = "Alabama"; $state["Alabama"] = "Montgomery"; $myState = array('name' => 'Texas', 'Capital' => 'Austin'); $myState['name']; // prints Texas
That was our first intro into the PHP language, but be sure to check back often as I will be continuing to dive into PHP. The next post is going to be all about variables!
Jas Singh is a Technical Lead for Fellowship Technologies. He has been with Fellowship Technologies since July 2007. He believes that every new day brings opportunities to learn something new.
- Include Requirements & Contribution Sub Types
- User Case Story from Hope Community Church
- Group Search Categories and More
- Account Creation
- Single Sign On Functionality Exposed
- API Communication Value Changes
- API Enhancement: Create and Edit Groups!
- API Enhancement: Requirements Exposed
- Resource Versioning
- Enter Visitor Data via Your Church Website
- Fellowship One & Planning Center Online
- API Libraries and Sample Code
- Building a custom login for your church website using the API
- Roll Foward!
- The Agile Triangle
- Conversation Paralysis
- Picture this, image updates & creates through the REST API
- A REST API double shot : Groups and Events realms
- Increasing Software Delivery by 500%
- Quick people API realm update
- Introducing the new REST API giving realm
- Raising the bar…
- Building a Deployment Pipeline
- The World of Dev Craft
- Running Tests in Parallel with Selenium
- Abstracting Your Code to Remove Duplication
- Documentation in an Agile Environment
- Drowning in Debt
- Intro to Ruby on Rails
- API Strategy & Roadmap
- Staging/Sandbox Environment is Back up!
- Downtime in Sandbox/Staging Environment
- Android & OAuth
- F1 API Static Library with Objective-c
- Programming in F#
- NoSQL: HuMONGOus Benefits (Part 2)
- Our Scrum Team Structure
- SaaS & BI - The History & Future
- Getting Started with Android
- NoSQL: Leaving Schema Behind (Part 1)
- Your Feedback…and a $25 Gift Card!
- A Scrum Ceremony? Is this a wedding or something?
- Variables in PHP
- Data Exchange API Fixes
- F1 Check-in on the iPad
- Be the first to get the news & tips!
- An Introduction to PHP
- Working with Pop Up Windows in Selenium
- List Comprehension
- Source Control: A Time Machine For Your Source Code
- Developer Conference…Lower Price, Same Great Content!
- The Quality Assurance Team
- How does Fellowship Technologies manage complex projects?
- Developer Conference coming in May!
- Sandbox Refresh Complete
- Sandbox Refresh This Week
- Updates coming to the REST API
- Sandbox Environment Down Time
- F1Touch :: Fellowship One On The Go
- Under the Hood
- Sandbox Refresh Complete
- Sandbox Refresh Tomorrow (Oct. 2nd)
- Fellowship One Developer Forums
- Ten Commandments of API Consumption
- REST API Enhancements / Fixes deployed to Sandbox and Production 09.09.09
- Data Exchange URL cut-over complete
- Important Data Exchange URL changes
- Ron Nom Nom
- How to get started using the REST API