Php basics

10,975 views
10,747 views

Published on

Published in: Technology
1 Comment
2 Likes
Statistics
Notes
  • IT Pathshala, Noida-Sector-63, offers Guaranteed JOB with PHP Training Programs.

    PAY US ONLY IF YOU GET A JOB!

    CALL US - +91-9871350999 or +91-8800394970

    Technology Centre Address: H-110, Sector-63, Noida (UP)

    Program Takeaways:

    - GUARANTEED JOB in your technology domain
    - Live Major Project development
    - Experience Letter on Training Completion
    - Certification on Training Completion
    - Project Source Code available in CD

    Program Highlights:

    - 100% Guaranteed Job – Don’t pay us if you don’t get a JOB!
    - Industry Ready Courses
    - LIVE International Project Experience
    - Exposure to corporate culture at our IT services facility
    - Networking & Interaction with Industry Experts
    - Training Provided by a reputed IT Company
    - Live Project Source Code made available in CD
    - Technology certification and experience letter at program completion
    - Online Study Content

    CALL US - +91-9871350999 or +91-8800394970

    Our website: www.itpathshala.com
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
10,975
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
56
Comments
1
Likes
2
Embeds 0
No embeds

No notes for slide

Php basics

  1. 1. PHP BasicsJamshid HashimiTrainer, Cresco Solutionhttp://www.jamshidhashimi.comjamshid@netlinks.af@jamshidhashimiajamshidhashimiAfghanistan WorkforceDevelopment Program
  2. 2. AGENDA• About PHP & MySQL• Advantage of using PHP for Web Development• PHP Installation, PHP Syntax & PHP Variable• PHP Strings• PHP Operators• Conditional Statements– if (...else) Statement– Switch Statements• Exercise!
  3. 3. PHP: Introduction• PHP is a programming language for buildingdynamic, interactive Web sites. As a generalrule, PHP programs run on a Web server, andserve Web pages to visitors on request. One ofthe key features of PHP is that you can embedPHP code within HTML Web pages, making itvery easy for you to create dynamic contentquickly.
  4. 4. PHP: Introduction• PHP stands for PHP: Hypertext Preprocessor,which gives you a good idea of its corepurpose: to process information and producehypertext (HTML) as a result.• PHP is a server-side scripting language, whichmeans that PHP scripts, or programs, usuallyrun on a Web server. (A good example of aclient-side scripting language is JavaScript,which commonly runs within a Web browser.)
  5. 5. PHP: The Process• A visitor requests a Web page by clicking a link, ortyping the page’s URL into the browser’s address bar.The visitor might also send data to the Web server atthe same time, either using a form embedded in a Webpage, or via AJAX (Asynchronous JavaScript And XML).• The Web server recognizes that the requested URL is aPHP script, and instructs the PHP engine to process andrun the script.• The script runs, and when it’s finished it usually sendsan HTML page to the Web browser, which the visitorthen sees on their screen.
  6. 6. PHP• PHP: Hypertext Preprocessor• Appeared in: 1995; 18 years ago• Designed by: Rasmus Lerdorf• Developer: The PHP Group• Stable release: 5.4.15 (May 9, 2013; 25 days ago)• Typing discipline: Dynamic, weak• Influenced by: Perl, C, C++, Java, Tcl• Implementation language: C• OS: Cross-platform• License: PHP License• Usual filename extensions .php, .phtml, .php4 .php3,.php5, .phps
  7. 7. Why PHP?• Easy to learn• Familiarity with syntax• Free of cost• Efficiency in performance• A helpful PHP community• Cross Platform
  8. 8. MySQL• MySQL is the most popular database system used with PHP.• MySQL is a database system used on the web• MySQL is a database system that runs on a server• MySQL is ideal for both small and large applications• MySQL is very fast, reliable, and easy to use• MySQL supports standard SQL• MySQL compiles on a number of platforms• MySQL is free to download and use• MySQL is developed, distributed, and supported by OracleCorporation• MySQL is named after co-founder Monty Wideniuss daughter: My
  9. 9. PHP Editor + W(M)AMP Installation
  10. 10. PHP Syntax• Basic PHP Syntax<?php// PHP code goes here?><!DOCTYPE html><html><body><h1>My first PHP page</h1><?phpecho "Hello World!";?></body></html>
  11. 11. PHP Variables• Variables are a fundamental part of anyprogramming language. A variable is simply acontainer that holds a certain value.echo 2 + 2;echo 5 + 6;echo $x + $y;
  12. 12. PHP Variables• A variable starts with the $ sign, followed by thename of the variable• A variable name must begin with a letter or theunderscore character• A variable name can only contain alpha-numericcharacters and underscores (A-z, 0-9, and _ )• A variable name should not contain spaces• Variable names are case sensitive ($y and $Y aretwo different variables)
  13. 13. Strings: ExamplesValid examples of strings:$string1 = "This is a string in doublequotes";$str = This is a somewhat longer, singlyquoted string;$string2 = ""; // a string with zerocharacters
  14. 14. Strings: ExamplesSingle quote strings vs. Double quote strings:$variable = "name";$text = "My $variable will print!";echo $text;> My name will print!$text = My $variable will not print!;echo $text;> My $variable will not print!
  15. 15. Strings: Concatenation(.)• String concatenation is the stringmanipulation method when you join 2 ormore strings together.$str1 = ”AWD Training";$str2 = "-Cresco Solutions";echo $str1.$str2;> AWD Training-Cresco Solutions
  16. 16. Strings: strlen()• Returns the length of the string$str = "Kabul is the capital ofAfghanistan";echo strlen($str);> 35
  17. 17. Strings: explode()• explode — Split a string by string$str = "This is a somewhat longer, singlyquoted string";$new_str = explode(" ",$str);print_r($new_str);>Array ( [0] => This [1] => is [2] => a [3]=> somewhat [4] => longer, [5] => singly[6] => quoted [7] => string )
  18. 18. Strings: strpos()• strpos — Find the position of the firstoccurrence of a substring in a string$str = "Kabul is the capital ofAfghanistan";$position = strpos($str,"capital");echo $position;> 13
  19. 19. Strings: strtoupper()• strtoupper — Make a string uppercase$str = "Kabul is the capital of Afghanistan";echo strtoupper($str);> KABUL IS THE CAPITAL OF AFGHANISTAN
  20. 20. Strings: strtolower()• strtolower — Make a string lowercase$str = "Kabul is the capital ofAfghanistan";echo strtolower($str);> kabul is the capital of afghanistan
  21. 21. Strings: ucfirst()• ucfirst — Make a strings first characteruppercase$str = "afghanistan";echo ucfirst($str);> Afghanistan
  22. 22. Strings: lcfirst()• lcfirst — Make a strings first characterlowercase$str = "Afghanistan";echo lcfirst($str);> afghanistan
  23. 23. Strings: trim()• trim — Strip whitespace (or other characters)from the beginning and end of a string$str = ” Afghanistan is the heart ofAsia";var_dump($str);>string(36) “Afghanistan is the heart ofAsia"$str = ” Afghanistan is the heart ofAsia";var_dump(trim($str));> string(32) "Afghanistan is the heart ofAsia”
  24. 24. Strings: str_replace()• str_replace — Replace all occurrences of thesearch string with the replacement string$str = "Balkh is the capital ofAfghanistan";echo str_replace("Balkh","Kabul",$str);> Kabul is the capital of Afghanistan
  25. 25. Strings: substr()• substr — Return part of a string$str = "Afghanistan is the heart of Asia";echo substr($str,12);> is the heart of Asia$str = "Afghanistan is the heart of Asia";echo substr($str,12,12);> is the heart$str = "Afghanistan is the heart of Asia";echo substr($str,-4);> Asia
  26. 26. Operators• In all programming languages, operators areused to manipulate or perform operations onvariables and values.– PHP Arithmetic Operators– PHP Assignment Operators– PHP Incrementing/Decrementing Operators– PHP Comparison Operators– PHP Logical Operators
  27. 27. Operators: Arithmetic
  28. 28. Operators: Assignment
  29. 29. Operators: Increment & Decrement
  30. 30. Operators: Comparison
  31. 31. Operators: Logical
  32. 32. Conditional Statementsif (condition){code to be executed if condition is true;}if (condition){code to be executed if condition istrue;}else{code to be executed if condition isfalse;}
  33. 33. Conditional Statementsif (condition){code to be executed if condition is true;}else if (condition){code to be executed if condition is true;}else{code to be executed if condition is false;}
  34. 34. Conditional Statementsswitch (n){case label1:code to be executed if n=label1;break;case label2:code to be executed if n=label2;break;default:code to be executed if n is different from both label1and label2;}
  35. 35. Exercise!• Write a program called CheckPassFail whichprints "PASS" if the int variable "mark" is morethan or equal to 50; or prints "FAIL"otherwise.• Write a program called CheckOddEven whichprints "Odd Number" if the int variable“number” is odd, or “Even Number”otherwise.
  36. 36. Exercise!• Write a program which add, subtract, divideand multiply two number and show the resulton the screen.• Write a program to find the biggest positivenumber among a,b,c,d numbers• Write a program which returns the average ofgiven 3 number
  37. 37. Exercise!• Write a program which categorize peopleaccording to their work experience:0: Fresh Graduate1-3: Mid-Level4-8: Senior Level9-30: Superman• Write a program which outputs the quarter(Q1,Q2,Q3,Q4) of the year a given date is in.– e.g. 17 June 2013 output must be: Q2 2013
  38. 38. QUESTIONS?

×