Category Archives: PHP

Collection of php lessons, php topics, php exercises, php tutorials, php demos, php examples, php interview questions, php problems, php issues, php frameworks, php books, php tools, php resources

Image upload

In this project we have to develop a image upload functionality in PHP. The functionality can be used to allow the users to upload profile picture, or upload an image for any kind of product.

Image upload requirements

  • Image format should be only .jpg file
  • Image size should not exceed 20kb
  • Image dimension should be in a ratio of 4:3 for better rendering on mobile devices
  • Create a folder name users and store the upload file in this folder

Continue reading

Laravel

Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable, creative experience to be truly fulfilling. Laravel attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as authentication, routing, sessions, and caching.

Laravel aims to make the development process a pleasing one for the developer without sacrificing application functionality. Happy developers make the best code. To this end, we’ve attempted to combine the very best of what we have seen in other web frameworks, including frameworks implemented in other languages, such as Ruby on Rails, ASP.NET MVC, and Sinatra.

Laravel is accessible, yet powerful, providing powerful tools needed for large, robust applications. A superb inversion of control container, expressive migration system, and tightly integrated unit testing support give you the tools you need to build any application with which you are tasked.

Proven Foundation. Laravel is built on top of several Symfony components, giving your application a great foundation of well-tested and reliable code.

Click here to know more about Laravel

PHP Reference Book

Free PDF of PHP Reference Book

This is a great quick reference book that presents content and examples in a way that it serves both beginners and intermediate users alike. A must buy book!

Here you will find corrections, tips, clarifications, and samples related to the PHP reference book. You are encouraged, if you find an error or something that needs clarification, to post a comment to the blog so it can be addressed in a post and fixed for later versions (that’s what I call wishful thinking).

Click here to download free pdf of PHP reference book

if else condition

If else is a very important flow of any programming language. You use it very often in every small piece of every program that you write. Lot of large of chunks of code are executed based on a simple if else condition.

if else condition Tutorial

In this tutorial we will  write a if else condition in PHP to check the age of a user and display a message depending on the if else condition.

The code will display a message ‘you are an adult” if the age is greater than 18 or display a message ‘you are not an adult” if the age is less than 18.
1. Define a variable named age

2. Check if age is greater than 18, show a message “you are an adult”, otherwise show a message “you are not an adult”

Some uses and examples of if else condition

  • detect if a user is logged in
  • detect if the device if mobile or tablet or desktop
  • detect browsers and version

Selecting random element from PHP associative array

We will solve the exercise “Greet the guests” by selecting random element from PHP associative array

Here is the code with explanation as per the hints provided

 Selecting random element from PHP associative array – defining a Associative array

We define a php associative array named ‘guest’ that stores the name of the guest and the gender

Selecting random element from PHP associative array – randomly loading a element from the associative array

We make use of “array_name()” function that takes the array name as parameter to load one record randomly from the array. We store the guest name  and in php variable “guestName” and guest gender in a variable “guestGender”. We print the name and gender using the php ‘echo’ statement for testing.

Selecting random element from PHP associative array – checking the gender using if/else statement

Here we check the guest gender using the php if/else statement and greet the guest depending on the gender.

Greet the guests

In this exercise you have to greet the guests you have invited for your birthday party.

The guest list comprises of men, women, kids (boys and girls)

Your task is load the name of one guest randomly on every page refresh and greet the guests depending on their gender. for eg.

Greet the guests example

  1. Jane Austen is a women, so say Hello Mrs.. Austen
  2. George Orwell is a man, so say Hello Mr. Orwell
  3. Isaac Newton was knighted, so say Hello Sir Newton
  4. Zehen is a boy, so say Hello Master Zehen

Greet the guests hints

  • Create a 2 dimensional array named guest if you are coding in php. The array should store the name and gender.
  • Load one row/record randomly
  • Make use of if else condition to check the gender
  • Alternative you can also make use of switch case of check the gender

Write the code in your favorite programming language.

Greet the guests solutions

Validate a form using pure PHP

In this project we will validate a form using pure PHP.
The form can be used to make a new user register or sign up. The form consist of almost all the form fields that we use in our day to day projects.

Validate a form using pure PHP – Project requirements

  • Check for blank input type using php
  • Check the length of an input type using php
  • Check for duplicate values in php
  • Check for valid email format in php
  • Check for alphanumeric password in php
  • Check for numeric mobile number in php
  • Check for image upload and image format in php
  • Check for date of birth selection using select menu in php
  • Check for gender selection using radio button in php
  • Check for terms selection using check box in php

Continue reading