Learn PHP In 1 Day - Guru99

Transcription

Learn PHP in 1 DayBy Krishna RungtaCopyright 2019 - All Rights Reserved – Krishna RungtaALL RIGHTS RESERVED. No part of this publication may be reproduced ortransmitted in any form whatsoever, electronic, or mechanical, includingphotocopying, recording, or by any informational storage or retrievalsystem without express written, dated and signed permission from theauthor.

Table Of ContentChapter 1: What is PHP? Write your first PHP Program1.2.3.4.5.6.7.8.9.10.What is PHP?What is a Scripting Language?Programming Language Vs Scripting LanguageWhat does PHP stand for?Php SyntaxWhy use PHP?What is PHP used for & Market sharePHP vs Asp.Net VS JSP VS CFMLPHP File ExtensionsPHP Hello worldChapter 2: How to Download & Install XAMPP & NetBeans: PHP Tutorial1.2.3.4.5.6.7.8.9.10.What is XAMPP?Why use XAMPP?How to Download and Install XAMPPBasic Web server configurationXAMPP Control PanelConfigure XAMPPWhat is the best PHP IDE?Introduction to Netbeans IDECreating a new PHP project using the Netbeans IDERunning your first PHP Example

Chapter 3: PHP Data Types, Variables, Constant, Operators Tutorial1.2.3.4.5.6.PHP Data TypesPHP VariableUse of VariablesVariable Type CastingPHP ConstantPHP OperatorsChapter 4: PHP Comments, Include/Include once, Require/Require once1.2.3.4.5.6.7.Why use Comments?PHP CommentsPHP Include & PHP Include onceExample : Include / Include oncePHP Require & PHP require onceExample : RequirePhp include vs requireChapter 5: PHP Array: Associative, Multidimensional1.2.3.4.What is a PHP Array?Numeric ArraysPHP Associative ArrayPHP Multi-dimensional arrays These are arrays that contain othernested5. PHP Arrays: Operators6. PHP Array Functions

Chapter 6: PHP Control Structures: If else, Switch Case1. What is a control structure?2. PHP IF Else3. PHP Switch CaseChapter 7: PHP Loop: For, ForEach, While, Do While [Example]Chapter 8: PHP String Functions: substr, strlen, strtolower, explode, strpos,str replace1.2.3.4.5.6.What is a string?PHP Create stringsPHP Create Strings Using Double quotesPHP HeredocPHP NowdocPHP string functionsChapter 9: PHP Function: Numeric, Built in, String, Date, User Defined1.2.3.4.5.6.7.What is a Function?Why use Functions?Built in FunctionsString FunctionsNumeric FunctionsDate FunctionWhy use User Defined Functions?

Chapter 10: PHP Registration Form using GET, POST Methods with Example1.2.3.4.5.6.7.What is Form?When and why we are using forms?Create a formSubmitting the form data to the serverGET vs POST MethodsProcessing the registration form dataMore examplesChapter 11: PHP Session & PHP Cookies with Example1.2.3.4.5.6.7.8.9.What is Cookie?Why and when to use Cookies?Creating CookiesRetrieving the Cookie valueDelete CookiesWhat is a Session?Why and when to use Sessions?Creating a SessionDestroying Session VariablesChapter 12: PHP File() Function: File exists, Fopen, Fwrite, Fclose, Fgets,copy, unlink1.2.3.4.5.6.What is a File?PHP File Formats SupportPHP files FunctionsPHP File exists FunctionPHP Fopen FunctionPHP Fwrite Function

7.8.9.10.11.12.PHP Fclose FunctionTesting the codePHP Fgets FunctionPHP Copy FunctionDeleting a filePHP File get contents FunctionChapter 13: PHP Try Catch Example: Exception & Error Handling Tutorial1.2.3.4.5.6.7.What is an Exception?Why handle exception?PHP Error handlingError handling examplesDifference between Errors and ExceptionMultiple ExceptionsTesting the codeChapter 14: PHP Regular Expressions Tutorial: Preg match, Preg split,Preg replace1.2.3.4.5.6.What is a Regular Expressions?Regular expressions in PHPPHP Preg matchPHP Preg splitPHP Preg replaceMeta charactersChapter 15: How to Send Email using PHP mail() Function1. What is PHP mail?

2.3.4.5.Why/When to use the mail PHPSimple Mail Transmission Protocol (SMTP)Sanitizing email user inputsSecure MailChapter 16: PHP MySQLi Functions: mysqli query, mysqli connect,mysqli fetch array1.2.3.4.5.6.7.PHP mysqli connect functionPHP mysqli select db functionPHP mysqli query functionPHP mysqli num rows functionPHP mysqli fetch array functionPHP mysqli close functionPHP Data Access Object PDOChapter 17: PHP Object Oriented Programming (OOPs) concept Tutorialwith Example1.2.3.4.5.6.7.8.What is OOPs?Object Oriented Programming PrinciplesOOPs Concepts in PHPWhat is UML?How to Create a class in PHPHow implement Inheritance in PHPHow to Create object of the classTesting our applicationChapter 18: PHP Date & Time Function with Example1. What is PHP Date Function?

2.3.4.5.6.7.8.9.10.11.PHP Date Syntax & ExampleWhat is a TimeStamp?Getting a list of available time zone identifiersPHP set Timezone ProgrammaticallyPHP Mktime FunctionPHP Date function referencePHP Time parametersDay parametersMonth ParametersYear ParametersChapter 19: PHP Security Function: strip tags, filter var, Md5 and sha11.2.3.4.5.Potential security threatsPHP Application Security Best PracticesPHP strip tagsPHP filter var functionPHP Md5 and PHP sha1Chapter 20: PHP XML Tutorial: Create, Parse, Read with Example1.2.3.4.5.6.7.8.What is XML?What is DOM?XML ParsersWhy use XML?XML Document exampleHow to Read XML using PHPTesting our applicationHow to Create an XML document using PHP

9. Testing our applicationChapter 21: PHP Projects: Create an Opinion Poll Application1. Step 1) Database Connectivity2. Step 2) Coding our application3. Step 3) Testing our applicationChapter 22: PHP Ajax Tutorial with Example1.2.3.4.5.6.7.What is Ajax?Why use AJAX?How to Create an PHP Ajax applicationStep 1) Creating the index pageStep 2) Creating the frameworks pageStep 3) Creating the JS scriptStep 4) Testing our PHP Ajax applicationChapter 23: PHP MVC Framework Tutorial: CodeIgniter Example1.2.3.4.5.6.7.8.What is PHP MVC framework?PHP MVC Design PatternTypes of PHP MVC frameworkPorting the opinion poll application to CodeIgniterDatabase configuration settingsCreating Our ModelCreating Our ViewsTesting our application

Chapter 24: CakePHP Framework Tutorial for Beginners1.2.3.4.5.6.7.8.9.What is CakePHP?Why use CakePHP Framework?History of CakePHPFeatures of CakePHPCakePHP- Folder StructureConfiguration of CakePHPCake- PHP naming conventionsHow does MVC work in CakePHP?Disadvantages of using the CakePHP frameworkChapter 25: PHP vs JavaScript: Must Know Differences1.2.3.4.5.PHPJavaScriptPHP vs Java-ScriptRepositoryTrend of JavaScript vs PHP

Chapter 1: What is PHP?Write your first PHP ProgramWhat is PHP?PHP is a server side scripting language. that is used to develop Static websitesor Dynamic websites or Web applications. PHP stands for Hypertext Preprocessor, that earlier stood for Personal Home Pages.PHP scripts can only be interpreted on a server that has PHP installed.The client computers accessing the PHP scripts require a web browser only.A PHP file contains PHP tags and ends with the extension ".php".What is a Scripting Language?A script is a set of programming instructions that is interpreted at runtime.A scripting language is a language that interprets scripts at runtime. Scriptsare usually embedded into other software environments.The purpose of the scripts is usually to enhance the performance or performroutine tasks for an application.Server side scripts are interpreted on the server while client side scriptsare interpreted by the client application.

PHP is a server side script that is interpreted on the server while JavaScriptis an example of a client side script that is interpreted by the clientbrowser. Both PHP and JavaScript can be embedded into HTML pages.Programming Language Vs ScriptingLanguageProgramming languageHas all the features needed to develop completeapplications.The code has to be compiled before it can beexecutedDoes not need to be embedded into otherlanguagesScripting languageMostly used for routine tasksThe code is usually executed without compilingIs usually embedded into other softwareenvironments.What does PHP stand for?PHP means - Personal Home Page, but it now stands for the recursivebackronym PHP: Hypertext Preprocessor.PHP code may be embedded into HTML code, or it can be used incombination with various web template systems, web content managementsystem and web frameworks.Php SyntaxA PHP file can also contain tags such as HTML and client side scripts

such as JavaScript.HTML is an added advantage when learning PHP Language. You caneven learn PHP without knowing HTML but it’s recommended you atleast know the basics of HTML.Database management systems DBMS for database poweredapplications.For more advanced topics such as interactive applications and webservices, you will need JavaScript and XML.The flowchart diagram shown below illustrates the basic architecture of aPHP web application and how the server handles the requests.

Why use PHP?You have obviously head of a number of programming languages out there;you may be wondering why we would want to use PHP as our poison for theweb programming. Below are some of the compelling reasons.PHP is open source and free.Short learning curve compared to other languages such as JSP, ASPetc.Large community documentMost web hosting servers support PHP by default unlike other languagessuch as ASP that need IIS. This makes PHP a cost effective choice.PHP is regular updated to keep abreast with the latest technologytrends.Other benefit that you get with PHP is that it’s a server side scriptinglanguage; this means you only need to install it on the server and clientcomputers requesting for resources from the server do not need tohave PHP installed; only a web browser would be enough.PHP has in built support for working hand in hand with MySQL; thisdoesn’t mean you can’t use PHP with other database managementsystems. You can still use PHP withPostgresOracleMS SQL ServerODBC etc.PHP is cross platform; this means you can deploy your application on anumber of different operating systems such as windows, Linux, Mac OSetc.

What is PHP used for & Market shareIn terms of market share, there are over 20 million websites and applicationon the internet developed using PHP scripting language.This may be attributed to the points raised above;The diagram below shows some of the popular sites that use PHPPHP vs Asp.Net VS JSP VS CFMLASP – Active Server Pages, JSP – Java Server Pages, CFML – Cold FusionMarkup language The table below compares the various server side scriptinglanguages with PHP

FEATUREPHPLearning curveshortWeb hostingSupported byalmost all hostingserversASPJSPLonger thanLonger than PHPPHPNeedsdedicated Fairly supportedserverOpen sourceYesNoWeb servicessupportBuilt inIntegration withEasyHTMLMySQLsupportNativeUses the.NETframeworkFairlycomplexNeeds thirdpartydriversEasily extendedbyother languages YesYesUses add on librariesCFMLLonger than PHPNeeds dedicated serverBoth commercial and opensourceBuilt inFairly complexEasyNeeds third partydriversCurrent version has nativesupport. Older versions useODBCExtended usingNoJava classes andlibraries.YesPHP File ExtensionsFile extension and Tags In order for the server to identify our PHP files andscripts, we must save the file with the “.php” extension. Older PHP fileextensions include.phtml.php3.php4.php5.phpsPHP was designed to work with HTML, and as such, it can be embeddedinto the HTML code.

You can create PHP files without any html tags and that is called Pure PHPfile.The server interprets the PHP code and outputs the results as HTML code tothe web browsers.In order for the server to identify the PHP code from the HTML code, wemust always enclose the PHP code in PHP tags.A PHP tag starts with the less than symbol followed by the question mark andthen the words “php”.PHP is a case sensitive language, “VAR” is not the same as “var”.The PHP tags themselves are not case-sensitive, but it is stronglyrecommended that we use lower case letter. The code below illustratesthe above point. ?php ? We will be referring to the PHP lines of code as statements. PHP statementsend with a semi colon (;). If you only have one statement, you can omit thesemi colon. If you have more than one statement, then you must end eachline with a semi colon. For the sake of consistency, it is recommended thatyou always end your statement(s) with a semi colon. PHP scripts areexecuted on the server. The output is returned in form of HTML.

PHP Hello worldThe program shown below is a basic PHP application that outputs the words“Hello World!” When viewed in a web browser. ?phpecho "Hello world";? Output:Hello worldSummaryPHP stands for Hypertext pre-processorPHP is a server side scripting language. This means that it is executedon the server. The client applications do not need to have PHPinstalled.PHP files are saved with the ".php" file extension, and the PHPdevelopment code is enclosed in tags.PHP is open source and cross platform

PHP means - Personal Home Page, but it now stands for the recursive backronym PHP: Hypertext Preprocessor. PHP code may be embedded into HTML code, or it can be used in combination with various web template systems, web content management system and web frameworks. Php Syntax A PHP file c