Embedded PHP. Web services vs. embedded PHP. CSE 190 M (Web Programming), Spring 2008 University of Washington



Similar documents
How To Write A Web Programming Textbook

Introduction to Web Development

How To Write A Program In Php (Php)

HTML Fails: What No One Tells You About HTML

CS134 Web Site Design & Development. Quiz1

Web Development. Owen Sacco. ICS2205/ICS2230 Web Intelligence

Developing Your School Website

PHP Tutorial From beginner to master

How To Create A Web Page On A Windows (For Free) With A Notepad) On A Macintosh (For A Freebie) Or Macintosh Web Browser (For Cheap) On Your Computer Or Macbook (

ICT. PHP coding. Universityy. in any

4PSA DNS Manager Translator's Manual

XML. CIS-3152, Spring 2013 Peter C. Chapin

CSE 203 Web Programming 1. Prepared by: Asst. Prof. Dr. Maryam Eskandari

Chapter 1 Programming Languages for Web Applications

Certified PHP Developer VS-1054

Last Week. XML (extensible Markup Language) HTML Deficiencies. XML Advantages. Syntax of XML DHTML. Applets. Modifying DOM Event bubbling

This tutorial assumes that you are familiar with ASP.Net and ActiveX controls.

WWW. World Wide Web Aka The Internet. dr. C. P. J. Koymans. Informatics Institute Universiteit van Amsterdam. November 30, 2007

RARITAN VALLEY COMMUNITY COLLEGE ACADEMIC COURSE OUTLINE CISY 233 INTRODUCTION TO PHP

Web Programming Step by Step

Web Design Course. Home Page. Join in. Home. Objectives. Course Content. Assignments & Discussion. Grades. Help. Contact Me aab43@uakron.

How To Write A Web Page In Html

Short notes on webpage programming languages

An Newsletter Using ASP Smart Mailer and Advanced HTML Editor

How To Use Dreamweaver With Your Computer Or Your Computer (Or Your Computer) Or Your Phone Or Tablet (Or A Computer)

PHP and XML. Brian J. Stafford, Mark McIntyre and Fraser Gallop

Dreamweaver Tutorial - Dreamweaver Interface

Web Programming Step by Step

How To Create A Website Template On Sitefinity

URLs and HTTP. ICW Lecture 10 Tom Chothia

Search Engine Optimisation (SEO) Guide

Introduction to Web Technologies

How To Create A Personalized Website In Chalet.Ch

HTML Fundamentals IN THIS APPENDIX

But have you ever wondered how to create your own website?

Introduction to web development

Web Development Guide. Information Systems

Introduction to web development and JavaScript

Basic Website Maintenance Tutorial*

Web Design Certification

WEB DEVELOPMENT IA & IB (893 & 894)

Course Information Course Number: IWT 1229 Course Name: Web Development and Design Foundation

Standard Checkout. Button Creation Wizard Implementation Guide. U.S. Version

Agenda. 1. ZAPms Konzept. 2. Benutzer-Kontroller. 3. Laout-Aufbau. 4. Template-Aufbau. 6. Konfiguration. 7. Module.

LAB MANUAL CS (22): Web Technology

JBoss Portlet Container. User Guide. Release 2.0

Advanced Web Design. Zac Van Note.

JISIS and Web Technologies

Gmail's new compose and reply experience

BUILDING MORE ACCESSIBILE SITES. SharePoint 2010

We automatically generate the HTML for this as seen below. Provide the above components for the teaser.txt file.

WIRIS quizzes web services Getting started with PHP and Java

TagSoup: A SAX parser in Java for nasty, ugly HTML. John Cowan (cowan@ccil.org)

10CS73:Web Programming

MyMobileAPI. mymobileapi.com. to SMS - Alternate sending option

HTML Basics(w3schools.com, 2013)

Fast track to HTML & CSS 101 (Web Design)

Web Development CSE2WD Final Examination June (a) Which organisation is primarily responsible for HTML, CSS and DOM standards?

Standard Languages for Developing Multimodal Applications

Interspire Website Publisher Developer Documentation. Template Customization Guide

ISI ACADEMY Web applications Programming Diploma using PHP& MySQL

STATEMENT OF PURPOSE

Macromedia Dreamweaver 8 Developer Certification Examination Specification

Copyright 2013 wolfssl Inc. All rights reserved. 2

Facebook - Twitter - Google +1 all in one plugin for Joomla enable "Twitter button", "Google +1

Advanced Web Development SCOPE OF WEB DEVELOPMENT INDUSTRY

How will the transition to the new Adobe Forums be handled?

JavaScript: Introduction to Scripting Pearson Education, Inc. All rights reserved.

Working With Templates in Web Publisher. Contributed by Paul O Mahony Developer Program

OpenStreetMap for Web Developers. Serge Wroclawski State of the Map US August 2010

Intro to Web Design. ACM UIUC

Software Requirements Specification For Real Estate Web Site

HTML and CSS. Elliot Davies. April 10th,

Specialized Programme on Web Application Development using Open Source Tools

VIRTUAL LABORATORY: MULTI-STYLE CODE EDITOR

Apple URL Scheme Reference

Script Handbook for Interactive Scientific Website Building

Web Programming Step by Step

JJY s Joomla 1.5 Template Design Tutorial:

RexxExpat An Introduction

IE Class Web Design Curriculum

MAXMAILER USER GUIDE

Enduring Understandings: Web Page Design is a skill that grows and develops throughout the careful planning and study of software and design.

Web Development using PHP (WD_PHP) Duration 1.5 months

.NET Best Practices Part 1 Master Pages Setup. Version 2.0

HTML5 & CSS3. ( What about SharePoint? ) presented

Penetration Testing with Selenium. OWASP 14 January The OWASP Foundation

Differences between HTML and HTML 5

MyCompany Professional Web Developer Certification Examination Specification

Intro to Web Development

Transcription:

Embedded PHP CSE 190 M (Web Programming), Spring 2008 University of Washington Except where otherwise noted, the contents of this presentation are Copyright 2008 Marty Stepp and Jessica Miller and are licensed under the Creative Commons Attribution 2.5 License. Web services vs. embedded PHP the PHP programs we've written so far were web services (their output is plain text) most PHP programs actually produce HTML as their output example: responses to HTML form submissions an embedded PHP program is a file that contains a mixture of HTML and PHP code

A bad way to produce HTML in PHP print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\n"; print " \"http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd\">\n"; print "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"; print " <head>\n"; print " <title>my web page</title>\n"; printing HTML code with print statements is ugly and error-prone: must quote the HTML and escape special characters, e.g. \" must insert manual \n line breaks after each line don't print HTML; it's bad style! Syntax for embedded PHP html content PHP code html content any contents of a.php file that are not between and are output as pure HTML can switch back and forth between HTML and PHP "modes"

Embedded PHP example <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><title>cse 190 M: Embedded PHP</title></head> <h1>geneva's Counting Page</h1> print "$i\n"; the above code would be saved into a file such as count.php How many lines of numbers will appear? (View Source!) Embedded PHP as form response <h1>new account created.</h1> <p> $name = $_REQUEST["name"]; $email = $_REQUEST["email"]; print "\"Thank you\", $name, for creating an account with $email.\n"; users expect an HTML response page when they submit forms embedded PHP allows you run some server-side code and also send back an HTML response page

Embedded PHP + print = bad <h1>geneva's Counting Page</h1> print "$i\n"; best PHP style is to use as few print/echo statements as possible in embedded PHP code but without print, how do we insert dynamic content into the page? PHP expression blocks <?= expression <h2>the answer is <?= 6 * 7 </h2> The answer is 42 PHP expression block: a small piece of PHP that evaluates and embeds an expression's value into HTML <?= expression is equivalent to: print expression; useful for embedding a small amount of PHP (a variable's or expression's value) in a large block of HTML without having to switch to "PHP-mode"

Expression block example 1 $name = $_REQUEST["name"]; $email = $_REQUEST["emailaddress"]; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><title>account Creation</title></head> <h1>new account created.</h1> <p> Thank you, "<?= $name ", for creating an account with <?= $email. expression blocks get rid of print statement in previous example can often move PHP code up, out of the middle of the HTML Expression block example 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><title>cse 190 M: Embedded PHP</title></head> for ($i = 99; $i >= 1; $i--) { <p> <?= $i bottles of beer on the wall, <br /> <?= $i bottles of beer. <br /> Take one down, pass it around, <br /> <?= $i - 1 bottles of beer on the wall. this code could go into a file named beer.php

Common error: unclosed braces <?= $i if you open a { brace, you must have a matching brace later (in the same PHP-mode block or a later one) and above are inside the for loop, which is never closed if you forget to close your braces, you'll see an error about 'unexpected $end' Common error fixed # PHP mode <?= $i <!-- HTML mode --> # PHP mode

Common error: Missing = sign <? $i a block between <? is often interpreted as the same as one between PHP evaluates the code, but $i does not produce any output Complex expression blocks for ($i = 1; $i <= 3; $i++) { <h<?= $i >This is a level <?= $i heading.</h<?= $i > <h1>this is a level 1 heading.</h1> <h2>this is a level 2 heading.</h2> <h3>this is a level 3 heading.</h3> expression blocks can even go inside HTML tags and attributes