Web Technologies and Programming Lecture 22 Introduction to PHP (Part 1)
Setting the environment
PHP overview
What is a PHP File
Open-source
Platform independent
What Can PHP Do?
Why PHP?
Basic PHP Syntax
Writing and Executing PHP Code
PHP constants
Constants are Global
PHP variables
Local
Global
Static
Type Determination
PHP Strings
PHP is a Loosely Typed Language
55 trang |
Chia sẻ: hoant3298 | Lượt xem: 599 | Lượt tải: 0
Bạn đang xem trước 20 trang tài liệu Web Technologies and Programming Lecture 22 Introduction to PHP (Part 1), để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
1Web Technologies and ProgrammingLecture 22Introduction to PHP (Part-1)2Summary of Previous LectureIntroduction to jQueryWhy use jQueryJquery:SyntaxSelectorsElement SelectorsClass SelectorsEventsEffects3Summary of Previous LectureDOMDOM ObjectsWindowNavigatorLocationHistoryDocumentXMLComponents of XML4OutlineSetting the environmentOverview of PHPConstants and Variables in PHPPHP stringsPHP is loose typed language 51. Setting The Environment A Web ServerPHP MySql DreamweaverAdobe DreamweaverNotepad / Notepad++6WAMP ServerWindows, Apache, MySQL, PHP1. Setting The EnvironmentChecking WAMP status:If this Icon is Red or Orange, it means it is not working properly.MSVCR100.dll is missingInstall Microsoft Visual C++ 2010 SP1 Redistributable PackagePort conflict with SkypePort conflict with IIS Express (if Visual Studio is installed)7WAMP Is Working Properly1. Setting The EnvironmentResolving Port Issues (If there is port issue):Click the icon of WAMP ServerExpand Apache sectionOpen httpd.conf file in NotepadPress Ctrl+F and type 80Wherever you find occurrence of 80, change it to 81Save the fileClick the icon of WAMP Server and Select Start All ServicesOpen Your Browser, type localhost:81 and it should display homepage of WampServer81. Setting The Environment92. PHP: an OverviewPHP: Hypertext PreprocessorOriginally called “Personal Home Page Tools”Used to create dynamic web pagesPopular server-side scripting technologyOpen-sourceAnyone may view, modify and redistribute source codePlatform independentPHP is a widely-used scripting language102. PHP: an OverviewWhat is a PHP File?PHP files can contain text, HTML, CSS, JavaScript, and PHP codePHP code are executed on the server, and the result is returned to the browser as plain HTMLPHP files have extension ".php“PHP scripts are executed on the server.112. PHP: an OverviewPHP:Interpreted language, scripts are parsed at run-time rather than compiled beforehandCompatible with many popular databasesPopular server-side scripting technologyStructurally similar to C/C++Supports procedural and object-oriented paradigm 122. PHP: What Can PHP Do?PHP:PHP can generate dynamic page contentPHP can create, open, read, write, delete, and close files on the serverPHP can collect form dataPHP can send and receive cookiesPHP can add, delete, modify data in your databasePHP can be used to control user-accessPHP can encrypt data132. PHP: Why PHP?PHP:PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)PHP is compatible with almost all servers used today (Apache, IIS, etc.)PHP supports a wide range of databasesPHP is free. Download it from the official PHP resource: www.php.netPHP is easy to learn and runs efficiently on the server side142. PHP: an Overview152. PHP: Basic PHP SyntaxPHP:A PHP script can be placed anywhere in the document.A PHP script starts with :Syntax:162.1 How PHP Fits with HTMLEmbedding PHP in HTML codeHTML can also be written inside the PHP codePHP can also be written as a standalone program with no HTML at all172.2 Basic Rules of PHP SyntaxPHP code is denoted in the page with opening and closing tags, as follows: PHP statements end with a semicolonComments can be added as// for one line comment/* and */ for multiple lines comment182.2 Basic Rules of PHP Syntax192.3 Writing and Executing PHP CodeOpen a Notepad/Notepad++ or Dreamweaver FileWrite PHP CodeSave file with .php extensionSave all the files in one directoryCopy this directory in C:\wamp\www\This is the directory from where wampserver access files202.3 Writing and executing PHP codeStart WAMP serverGo to localhost either by typing localhost in address bar of the browser or by clicking the WAMP sever icon in the toolbar and selecting localhostSelect your web directory from the list of project on the WAMP server home pageSelect the file to execute212.3 COMMENTS IN PHP codeA comment in PHP code is a line that is not read/executed as part of the program. Its only purpose is to be read by someone who is looking at the code.Comments can be used to:Let others understand what you are doingRemind yourself of what you did - Most programmers have experienced coming back to their own work a year or two later and having to re-figure out what they did. Comments can remind you of what you were thinking when you wrote the codePHP supports several ways of commenting:222.3 COMMENTS IN PHP codeExample232.4 Writing output to the browserecho(): is used to write output on the browserecho(“Welcome to PHP”); echo “Welcome to PHP”;print(): can also be used to write out put on the browserprint(“Welcome to PHP”); print “Welcome to PHP”;printf(): can also be used for writing output242.5 First PHP program25PHP Block StartsWriting on BrowserEnding PHP Block2.5 First PHP program26Output from PHP Code2.6 Integrating HTML with PHP27echo statement outputs whatever it’s told to the browserIt can output not only plain text but also HTML tags echo “ Welcome to the PHP”;2.6 Integrating HTML with PHP28Using quotation marks:echo “ Welcome to PHP”; echo “ Welcome to PHP”; echo “ Welcome to PHP”; 2.6 Integrating HTML with PHP29Using Heading TagArranging QuotationsUsing Escape Character2.6 Integrating HTML with PHP303. Using CONSTANTS and Variables313.1 ConstantsA constant is a placeholder for a value that you reference within your code that is formally defined before using itmust begin with a letter or an underscoreare case sensitivetypically they are named using all capital lettersPHP function define() is used to assign a value to a constant323.1 ConstantsParameters:name: Specifies the name of the constantvalue: Specifies the value of the constantcase-insensitive: Specifies whether the constant name should be case-insensitive. Default is false333.1 Constants34Constant NameValue of ConstantDisplaying The Value 3.1 Constants353.2 Constants are GlobalConstants are automatically global and can be used across the entire script.The example below uses a constant inside a function, even if it is defined outside the function:Example: 363.2 VariablesVariables are "containers" for storing information.Variables can store data of different types, and different data types can do different things.373.2 VariablesBegin with $ signFirst character must be a letter or underscoreRemaining characters may be letters, numbers or underscoresDon’t need to declare or initializeCase Sensitive ( $age and $AGE) A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )Data types does not require to be declare explicitlySupportsFloat, Integer, Boolean, String, Array, Object 383.2 VariablesPHP has three different variable scopes:LocalA variable declared within a function has a LOCAL SCOPE and can only be accessed within that functionGlobalA variable declared outside a function has a GLOBAL SCOPE and can only be accessed outside a functionStaticwhen a function is completed/executed, all of its variables are deleted. However, sometimes we want a local variable NOT to be deleted. We need it for a further job.To do this, use the static keyword when you first declare the variable393.2 VariablesData Types Supported by PHPFloat (floating point numbers - also called double)Integer ( -2,147,483,648 and 2,147,483,647) Boolean ( TRUE or FALSE.) StringArray (An array stores multiple values in one single variable ) .Object (An object is a data type which stores data and information on how to process that data. an object must be explicitly declared an object must be explicitly declared ).403.2 Variables41Variable DeclaredInitial ValueDisplaying Variable’s Value3.2 Variables423.2 VariablesThe gettype() Functionreturns the type of Provided VariableThe settype() Functionconverts a variable to the type specified by type433.2 Variables44Get Type FunctionSet Type FunctionGet Type Function2.2 Variables452.2.1 Type DeterminationA number of functions are available for determining a variable’s typeIt will return 1 if conditions satisfies so these are Boolean functions.Syntax:is_name($variable_name)462.2.1 Type DeterminationSome of the common functions are:is_array()is_bool()is_float()is_integer() is_null() is_numeric()is_string()472.2.1 Type determination482.2.1 Type determination493. PHP Strings50A string is a sequence of characters, like "Hello world!".PHP String FunctionsNow, we will look at some commonly used functions to manipulate strings.Get The Length of a StringThe PHP strlen() function returns the length of a string.The example below returns the length of the string "Hello world!":3. PHP Strings51Count The Number of Words in a StringThe PHP str_word_count() function counts the number of words in a string:Reverse a StringThe PHP strrev() function reverses a string:4. PHP is a Loosely Typed Language52In the example below, notice that we did not have to tell PHP which data type the variable is.PHP automatically converts the variable to the correct data type, depending on its value.In other languages such as C, C++, and Java, the programmer must declare the name and type of the variable before using it.ExampleSummary of Today’s LectureSetting the environmentPHP overviewWhat is a PHP FileOpen-sourcePlatform independentWhat Can PHP Do?Why PHP?Basic PHP SyntaxWriting and Executing PHP CodePHP constantsConstants are GlobalPHP variables LocalGlobalStaticType Determination53Summary of Today’s LecturePHP StringsPHP is a Loosely Typed Language54THANK YOU55
Các file đính kèm theo tài liệu này:
- lecture_22_wt_introduction_to_php_part_1_6521_2028584.pptx