1 / 16

Web Development

Web Development. PHP intro. What is it ?. PHP is a server side scripting language It is also a pre-processor as it processes web pages before sending them to the client There are other server side languages out there, but php is open source and therefore free!

finian
Download Presentation

Web Development

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Web Development PHP intro

  2. What is it? • PHP is a server side scripting language • It is also a pre-processor as it processes web pages before sending them to the client • There are other server side languages out there, but php is open source and therefore free! • Unicentre (actually Moodle) is written in php

  3. How to get it • Download and set up a portable version of EasyPHP on your USB drive so that you can take the server around with you and use it on any PC • A portable version of an application doesn’t amend the Windows’ registry (and so won’t appear in the Start menu)

  4. How HTML works user types in the URL (.htm) Request sent to server, HTML page returned HTML page parsed by the browser and displayed

  5. How php works user types in the URL (.php) Request sent to server, php processed and HTML page returned HTML page parsed by the browser and displayed

  6. How does it fit in with HTML? • php script is embedded within the HTML • because of this, all php is written inside tags • the php tags are <?php ……… ?> • php uses syntax that is very similar to C (and therefore also like Java) • for example, all php lines end in a semicolon ; • unlike HTML, it is a proper programming language that supports sequence, selection and repetition

  7. First php program <html> <head> <title>My first php program</title> <body> <?php echo “hello world”; ?> </body> </html>

  8. Notes • In html written in PowerPoint I omit the Doctype required by xHTML. • This is purely to keep the code manageable on screen • In the real world, you should use the doctype • echo prints to the html document that will be sent to the browser for parsing, effectively printing it on the screen as it is outside of any tag

  9. Coding Conventions • You should observe normal coding conventions, namely: • indent your code to make it readable • use comments (// or /*…..*/) • use meaningful variable names • Programming is usually a team pursuit and you will make yourself very unpopular if you write code that is illegible

  10. HTML with php <html> <head> <title>My first php program</title> <body> <?php echo “<h1>hello world</h1>”; ?> </body> </html>

  11. Integration Important note: • the phpgoes in the html, not the other way around • remember, php is written inside HTML tags! • the code on the following slide will work, but is incorrect and must be avoided:

  12. Integration <?php echo “<html>”; echo “<head>”; echo “<title>My first php program</title>”; echo “<body>”; echo “<h1>hello world</h1>”; echo “</body>”; echo “</html>”; ?>

  13. Variables • php is a loosely typed language • this means that you do not have to declare variables before using them • neither do you have to declare what type of data you want to store there – this will be sorted out automatically for you • all variables must start with a dollar sign $

  14. Variables • e.g. <?php $txt="Hello World!"; $x=16;?>

  15. Similarities to other languages • php has many built in functions • it will save you a lot of time if you get to know these and get used to looking to see if there is a function to do what you want to do before you write some code to do it! • There’s no point reinventing the wheel!

  16. Similarities to other languages • the loop functions (for, while, do…while) are the same as for C • the selection statements are the same as for C (if…else and case… switch) • arrays are very similar too

More Related