Web Design and Programming 2 Lecture 1 Dr
Web Design and Programming 2 Lecture 1 Dr. Mohammed Rasad
Outlines 2 Server-Side web programming What is PHP? PHP Editors Introduction to PHP Syntax PHP Outputs (print/echo) PHP Comments PHP Variables
Lectures download 3 URL: https: //drive. google. com/drive/folders/1 Kzh. LP Pu 3 h. BK 5 c. E 5 CAv 4 r. MRRUe. Wx 6 Dy. LS or Short link: http: //shorturl. at/oqry. W or
Server-Side web programming 4 Server-side pages are programs written using one of many web programming languages/frameworks examples: PHP, Java/JSP, Ruby on Rails, ASP. NET, Python, Perl
5 Server-Side web programming (cont. ) Web server: contains software that allows it to run server side programs sends back their output as responses to web requests we use PHP
What is PHP? 6 PHP stands for "PHP Hypertext Preprocessor" Server-side scripting language Used to make web pages dynamic: interface with other services: database, e-mail, etc. authenticate users process form information PHP code can be embedded in XHTML code
PHP Editors 7 Visual Studio Code Php. Storm Net. Beans Eclipse PDT Notpad Notepad++ Atom Bluefish …
Lifecycle of a PHP web request 8 Hello. php Hello world! User’s computer Server computer
Why PHP? 9 Free and open source Compatible Simple
What is PHP files ? 10 PHP files can contain text, HTML, CSS, Java. Script, and PHP code is executed on the server, and the result is returned to the browser as plain HTML PHP files have extension “. php”
Set Up PHP on Your Own PC 11 However, if your server does not support PHP, you must: install a web server install PHP install a database, such as My. SQL See the Tutorial. .
Hello World! 12 <? php. . . ? > PHP <? php echo "Hello, world!"; ? > PHP Hello world! output
PHP Case Sensitivity 13 In PHP, NO keywords (e. g. If, else, while, echo), classes, functions, and user-defined functions are case-sensitive. Note: However; all variable names are casesensitive! <? php ECHO "Hello World! "; echo "Hello World! "; Ec. Ho "Hello World! "; ? > PHP <? php $color = "red"; echo "My car is ". $color. " "; echo "My house is ". $COLOR. " "; echo "My boat is ". $co. LOR. " "; ? > PHP
Viewing PHP output 14 Hello world!
PHP syntax template 15 HTML content <? php PHP code ? > HTML content. . . PHP Contents of a. php file between <? php and ? > are executed as PHP code All other contents are output as pure HTML We can switch back and forth between HTML and PHP "modes"
Console output: print/echo 16 echo and print are more or less the same. They are both used to output data to the screen. The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters (although such usage is rare) while print can take one argument. echo is marginally faster than print "text"; echo "text"; PHP
Console output: print/echo 17 print "Hello, World!n"; print "Escape "chars" are the SAME as in Java!n"; print "You can have line breaks in a string. "; print 'A string can use "single-quotes". It's cool!'; echo line echo "Hello, World!n"; "Escape "chars" are the SAME as in Java!n"; "You can have breaks in a string. "; 'A string can use "single-quotes". It's cool!'; PHP Hello world! Escape "chars" are the SAME as in Java! You can have line breaks in a string. A string can use "single-quotes". It's cool! output
Variables 18 $name = expression; PHP $user_name = “ahmed 123"; $age = 16; $drinking_age = $age + 5; $this_class_rocks = TRUE; PHP Variables names are case sensitive ($age is not $Age) Variables names always begin with $, on both declaration and usage
Comments 19 # single-line comment // single-line comment /* multi-line comment */ PHP like Java, but # is also allowed a lot of PHP code uses # comments instead of //
Variables 20 In PHP, a variable starts with the $ sign, followed by the name of the variable <? php $txt = "Hello world!"; $x = 5; $y = 10. 5; ? > PHP
Variables 21 Rules for PHP variables: A variable starts with the $ sign, followed by the name of the variable A variable name must start with a letter or the underscore character A variable name cannot start with a number A variable name can only contain alphanumeric characters and underscores (A-z, 0 -9, and _ ) Variable names are case-sensitive ($age and $AGE are two different variables)
Variables 22 basic types: int, float, boolean, string, array, object, NULL PHP converts between types automatically in many cases: string → int auto-conversion on + int → float auto-conversion on / type-cast with (type): $age = (int) "21";
Thank you. .
- Slides: 23