PHP Tutorial

PHP is the most popular server-side scriptiong language for creating dynamic web pages.

PHP stands for Hypertext Preprocessor. PHP is a very popular and widely-used open source server-side scripting language to write dynamically generated web pages. PHP was originally created by Rasmus Lerdorf in 1994. It was initially known as Personal Home Page.

PHP scripts are executed on the server and the result is sent to the web browser as plain HTML. PHP can be integrated with the number of popular databases, including MySQL, PostgreSQL, Oracle, Microsoft SQL Server, Sybase, and so on. The current major version of PHP is 7. All of the code in this tutorial has been tested and validated against the most recent release of PHP 7.

PHP is very powerful language yet easy to learn and use. So bookmark this website and continued on.

What You Can Do with PHP

There are lot more things you can do with PHP.

  • You can generate pages and files dynamically.
  • You can create, open, read, write and close files on the server.
  • You can collect data from a web form such as user information, email, phone no, etc.
  • You can send emails to the users of your website.
  • You can send and receive cookies to track the visitor of your website.
  • You can store, delete, and modify information in your database.
  • You can restrict unauthorized access to your website.
  • You can encrypt data for safe transmission over internet.

The list does not end here, there are many other interesting things that you can do with PHP. You will learn about all of them in detail in upcoming chapters.

Advantages of PHP over Other Languages

If you're familiar with other server-side languages like ASP.NET or Java, you might be wondering what makes PHP so special. There are several advantages why one should choose PHP.

Easy to learn: PHP is easy to learn and use. For beginner programmers who just started out in web development, PHP is often considered as the preferable choice of language to learn.

Open source: PHP is an open-source project. It is developed and maintained by a worldwide community of developers who make its source code freely available to download and use.

Portability: PHP runs on various platforms such as Microsoft Windows, Linux, Mac OS, etc. and it is compatible with almost all servers used today such Apache, IIS, etc.

Fast Performance: Scripts written in PHP usually execute or runs faster than those written in other scripting languages like ASP, Ruby, Python, Java, etc.

Vast Community: Since PHP is supported by the worldwide community, finding help or documentation related to PHP online is extremely easy.

What This Tutorial Covers

This PHP tutorial series covers all the fundamental programming concepts, including data types, operators, creating and using variables, generating outputs, structuring your code to make decisions in your programs or to loop over the same block of code multiple times, creating and manipulating strings and arrays, defining and calling functions, and so on.

Once you're comfortable with the basics, you'll move on to next level that explains the concept file system, sessions and cookies, dates and times, as well as how to send email from your script, handling and validating forms, perform data filtration and handling errors in PHP.

Finally, you'll explore some advanced concepts like classes and objects, parsing JSON data, pattern matching with regular expressions, exception handling as well as how to use PHP to manipulate data in MySQL database and create useful features like user login system, Ajax search, etc.

Setting up bootstrap

To get started with Bootstrap the first step is to download Bootstrap from http://getbootstrap.com. This website also has all the documentation you need to get started with bootstrap.

As of this article the version is 3.3.6. With the download you get a single zip folder which contains all the required bootstrap components.

Unzip the ZIP folder and you should see the following folder structure. Notice there are 3 sub-folders (css, fonts & js). Let us understand the use of each file, folder by folder.

bootstrap.css - This is the core css for BootStrap that defines all the style for various controls and components

bootstrap.css.map - When debugging the minified code, the line numbers do not refer to the orignal files. The file that has the .map extension which is also called as source map file fixes this problem by allowing the web debuggers to refer to the original context from where the code was generated. This file is useful during development.

bootstrap.min.css - This is the compressed version meaning all the whitespaces, line breaks and any other extra characters have been removed. As a result the size of the minified file is smaller than the non-minified file. Minified version is usually used on a production server for efficient download where as the non minified version is used in development environment as it is more readable and easy to debug if there are issues.

bootstrap.min.css.map - Source map file for bootstrap.min.css

bootstrap-theme.css - As the name suggests this is the theme for bootstrap. Adding the core bootstrap.css is enough for bootstrap to work. The theme file is optional and is usually used for a visually enhanced experience. For example if you want 3D effects, gradients, shadows etc.

bootstrap-theme.css.map - Source map file for bootstrap-theme.css

bootstrap-theme.min.css - Minified version of bootstrap-theme.css

bootstrap-theme.min.css.map - Source map file for bootstrap-theme.min.css

Files in "fonts" folder

There are 5 different font files from Glyphicons. These 5 different files are just different format of the Glyphicons font, to support different browsers.

Files in "js" folder : These JavaScript files are optional. These are required if you want to use bootstrap widgets like picture carousel, dropdown menus, collapsible accordian etc. One important thing to keep in mind is that boostrap JavaScript has a dependency on jQuery, so a reference to jQuery must also exist on the page where you want to use Bootstrap.

bootstrap.js - This is the non-minified readable version that is usually used during development.

bootstrap.min.js - Minified version of bootstrap.js optimised for faster download. This is the version that is usually used in a production environment.

npm.js - npm is a file from Node.js and is used for npm installing bootstrap. If you are new to Node.js, don't worry, this is not going to come in the way to understand bootstrap.

For this course I am going to use Visual Studio 2013 as the editor. You can use any editor of your choice.

Here are the steps to create your first web page with Bootstrap

1. Create a new empty ASP.NET web application project. Name it BootstrapDemo

2. To use bootstrap in your website, copy the folder that contains 3 sub-folders (css, fonts, & js) in your website project folder.

3. Add a new HTML file to the project. Name it index.html.

3. There is a basic template available at the following link. Copy and paste the template code in index.html http://getbootstrap.com/getting-started/#template

4. Finally modify the code in index.html as shown below, to make sure bootstrap is working as expected.

<!DOCTYPE html> <html lang=&quot;en&quot;> <head> <meta charset=&quot;utf-8&quot;> <meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;> <meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;> <title>Bootstrap Example</title> <link href=&quot;bootstrap/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot;> </head> <body> <h1 class=&quot;text-primary&quot;>Hello, Bootstrap!</h1> <script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js&quot;> </script> <script src=&quot;bootstrap/js/bootstrap.min.js&quot;></script> </body> </html>

Please note : The viewport meta tag ensure proper rendering and touch zooming on a mobile device.

5. At this point, the project structure in solution explorer should be as shown below.

What is bootstrap

Bootstrap is a free, open-source and is the most popular HTML, CSS, and JavaScript framework developed by twitter for creating responsive web applications.

It includes HTML and CSS based design templates for common user interface components like Buttons, Dropdowns, Typography, Tabs, Forms, Tables, Navigations, Alerts, Modals, Accordion, Carousel etc. along with optional JavaScript extensions.

Bootstrap framework is based on open standards - HTML, CSS and JavaScript. This means bootstrap can be used with any server side technology and any platform. You can use it with any web application built with any server side technology like ASP.NET, JAVA, PHP etc.

What are the advantages of using bootstrap

Supports responsive design : One of the greatest advantages of using bootstrap is that it helps us create responsive web applications faster and easier. So the obvious question that comes to our mind is, what is a responsive web application? A responsive web application automatically adapts to different screen sizes (i.e desktop computers, laptops, tablets. mobile phones etc). A responsive application provides optimal viewing and interaction experience i.e easy reading and navigation with a minimum of resizing, panning, and scrolling across a wide range of devices. So you don't have to worry about your application not being compatible with multiple devices.

Saves lot of development time : One of the biggest advantages of using Bootstrap is that it saves lot of development time. Instead of writing code from the scratch, bootstrap offers ready made blocks of code that you can use and customize to suit your application requirements. There are also many websites out there that offer free and paid Bootstrap themes that saves even more development time.

Consistency : Bootstrap was developed by Twitter to encourage consistency across thier internal tools by giving their developers a centralised development code. Since all the developers are working using a centralised code, the end result is consistent regardless of who’s working on the project and which web browser is being used.

Customizable : If you are using only a few features of bootstrap, you can customize to download only those features using the following bootstrap customize page.

http://getbootstrap.com/customize/

Support : As Bootstrap is the most popular framework, it has a very large community base and excellent documentation. Bootstrap's excellent documentation, examples and demos helps a developer learn bootstrap quickly even if you are new to it. If you ever run into an issue you will usually get help quickly and easily from the vast online community and web forums.

PHP Tutorial

PHP is the most popular server-side scriptiong language for creating dynamic web pages. PHP stands for Hypertext Preprocessor. PHP is a ver...