How To Write A Program In Php 2.5.2.5 (Php)



Similar documents
AT&T Global Network Client for Windows Product Support Matrix January 29, 2015

COMPARISON OF FIXED & VARIABLE RATES (25 YEARS) CHARTERED BANK ADMINISTERED INTEREST RATES - PRIME BUSINESS*

COMPARISON OF FIXED & VARIABLE RATES (25 YEARS) CHARTERED BANK ADMINISTERED INTEREST RATES - PRIME BUSINESS*

Analysis One Code Desc. Transaction Amount. Fiscal Period

Case 2:08-cv ABC-E Document 1-4 Filed 04/15/2008 Page 1 of 138. Exhibit 8

Enhanced Vessel Traffic Management System Booking Slots Available and Vessels Booked per Day From 12-JAN-2016 To 30-JUN-2017

PASTPERFECT-ONLINE DESIGN GUIDE

Assignment 4 CPSC 217 L02 Purpose. Important Note. Data visualization

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

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

Managing Users and Identity Stores

Importing and Exporting With SPSS for Windows 17 TUT 117

Introduction to Web Development

UNIVERSITY OF CALGARY Information Technologies WEBFORMS DRUPAL 7 WEB CONTENT MANAGEMENT

Website Development Komodo Editor and HTML Intro

How to Edit Your Website

OU Campus Web Content Management

Ashley Institute of Training Schedule of VET Tuition Fees 2015

Using Adobe Dreamweaver CS4 (10.0)

Content Management System User Guide

6.170 Tutorial 3 - Ruby Basics

Python Lists and Loops

Web Development. Owen Sacco. ICS2205/ICS2230 Web Intelligence

CENTERPOINT ENERGY TEXARKANA SERVICE AREA GAS SUPPLY RATE (GSR) JULY Small Commercial Service (SCS-1) GSR

Domain Name Abuse Detection. Liming Wang

Employers Compliance with the Health Insurance Act Annual Report 2015

Detailed guidance for employers

How to Create and Send a Froogle Data Feed

OCS Training Workshop LAB13. Ethernet FTP and HTTP servers

Campaign Manager 2.0 for Sitecore CMS 6.6

Overview. How It Works

VISUAL ALGEBRA FOR COLLEGE STUDENTS. Laurie J. Burton Western Oregon University

Consumer ID Theft Total Costs

Chapter 1 Introduction to web development and PHP

An Eprints Apache Log Filter for Non-Redundant Document Downloads by Browser Agents

CS 103X: Discrete Structures Homework Assignment 3 Solutions

CREATING WEB FORMS WEB and FORMS FRAMES AND

Search Engine Optimization (SEO) & Positioning

Advanced Web Development SCOPE OF WEB DEVELOPMENT INDUSTRY

SerialMailer Manual. For SerialMailer 7.2. Copyright Falko Axmann. All rights reserved.

API. Application Programmers Interface document. For more information, please contact: Version 2.01 Aug 2015

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

Search Engine optimization

COMP Upload File Management and Processing

Forensic Analysis of Internet Explorer Activity Files

MailForm Copyright 2000 Left Side Software Pty Ltd

Introduction to Ingeniux Forms Builder. 90 minute Course CMSFB-V6 P

Office of History. Using Code ZH Document Management System

Why File Upload Forms are a Major Security Threat

Search Engine Optimization (SEO) with Google

Magento module Documentation

Getting Started with KompoZer

Centers of Academic Excellence in Cyber Security (CAE-C) Knowledge Units Review

Portal Connector Fields and Widgets Technical Documentation

ITP 101 Project 3 - Dreamweaver

Using the Content Management System

1. Introduction. 2. User Instructions. 2.1 Set-up

Manual for CKForms component Release 1.3.4

Exam 3 Review/WIR 9 These problems will be started in class on April 7 and continued on April 8 at the WIR.

PDG Software. Site Design Guide

HTML Fails: What No One Tells You About HTML

by Jonathan Kohl and Paul Rogers 40 BETTER SOFTWARE APRIL

Supervisor Instructions for Approving Web Time Entry

Introduction to UNIX and SFTP

Adobe Dreamweaver Student Organizations Publishing Details Getting Started Basic Web Page Tutorial For Student Organizations at Dickinson College *

AD Phonebook 2.2. Installation and configuration. Dovestones Software

Building a Personal Website (Adapted from the Building a Town Website Student Guide 2003 Macromedia, Inc.)

Google Calendar 3 Version 0.8 and 0.9 Installation and User Guide. Preliminary Setup

CAFIS REPORT

Tableau Server Trusted Authentication

Introduction to Python

TRANSFORM YOUR MEDE8ER TV WALL FROM THIS: TO THIS: LIBRARY VIEW SHOW VIEW SEASON VIEW FULL SYNOPSIS AND INFO

Qlik REST Connector Installation and User Guide

Go Kiwi Internet Content Management System Version 5.0 (K5) TRAINING MANUAL

Microsoft Access Rollup Procedure for Microsoft Office Click on Blank Database and name it something appropriate.

Personal Portfolios on Blackboard

Interest Rates. Countrywide Building Society. Savings Growth Data Sheet. Gross (% per annum)

CS134 Web Site Design & Development. Quiz1

P/T 2B: 2 nd Half of Term (8 weeks) Start: 25-AUG-2014 End: 19-OCT-2014 Start: 20-OCT-2014 End: 14-DEC-2014

P/T 2B: 2 nd Half of Term (8 weeks) Start: 26-AUG-2013 End: 20-OCT-2013 Start: 21-OCT-2013 End: 15-DEC-2013

Lesson 6: Credit Reports and You Thought Your Report Card Was Important

P/T 2B: 2 nd Half of Term (8 weeks) Start: 24-AUG-2015 End: 18-OCT-2015 Start: 19-OCT-2015 End: 13-DEC-2015

ORACLE USER PRODUCTIVITY KIT USAGE TRACKING ADMINISTRATION & REPORTING RELEASE 3.6 PART NO. E

GUIDELINES FOR SCHOOL WEB PAGES

Advanced Drupal Features and Techniques

Internet Technologies. World Wide Web (WWW) Proxy Server Network Address Translator (NAT)

WHMCS MultiSite Module

Tableau Server Trusted Authentication

Creating Java EE Applications and Servlets with IntelliJ IDEA

Research Laboratory. Java Web Crawler & Hadoop MapReduce Anri Morchiladze && Bachana Dolidze Supervisor Nodar Momtselidze

Factoring Algorithms

SEO AND CONTENT MANAGEMENT SYSTEM

Intermediate Math Circles March 7, 2012 Linear Diophantine Equations II

Crystal Reports Integration Plugin for JIRA

Buckaroo Payment Engine 3.0 Implementation Manual HTML gateway

Transcription:

Exercises 1. Days in Month: Write a function daysinmonth that takes a month (between 1 and 12) as a parameter and returns the number of days in that month in a non-leap year. For example a call to daysinmonth(6) should return 30, because June has 30 days. Month Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Days 31 28 31 30 31 30 31 31 30 31 30 31 2. Vowel Count: Write a function called vowelcount which accepts a string as a parameter, and returns the number of vowels in the in string. Vowels include a, e, i, o, and u. You may assume the string will be all lowercase. 3. 1337 5p34k: Write a function leetspeak() which accepts a string as a parameter and returns a "leetspeak" version of the string. Leetspeak is an internet slang in which various English letters are replaced with other ASCII characters similar in appearance. The following table shows some common leetspeak translations. English A E G L O S T Leetspeak 4 3 9 1 0 5 7 You should replace at least English five characters with their leetspeak equivalent. For more information about leetspeak, visit http://en.wikipedia.org/wiki/leet. 4. Palindromes: Write a function ispalindrome that accepts a string as a parameter and returns true if the string is a palindrome and false otherwise. A string is considered a palindrome if it has the same sequence of letters when reversed (for example, "radar", "toot", "mom", "a", ""). Your function should be case-insensitive; for example, "Mom" and "RAdar" should be considered palindromes. 5. Drunken Capitalizer: Write a PHP function called drunkencapitalizer that accepts a String as a parameter and returns the same String with randomly capitalized characters. For example, drunkencapitalizer("php rules") could return PHP RULES, php rules, Php RULEs or PHP rules. Switching cases is not needed; you are only required to randomly capitalize letters. So calling drunkencapitalizer("php RULES") would only return PHP RULES. 6. Fix Spacing: Write a function called fixspacing which accepts a filename as a parameter. The function should reduce all multiple spaces or tabs to a single space, replacing the old contents of the file. Fox example, an input file could contain the following text: 1

2 Exercises four score and seven years ago our fathers brought on this a new forth continent nation After calling fixspacing, the contents of the file should be as follows: four score and seven years ago our fathers brought forth on this continent a new nation Each word is to appear on the same line in new file as it appears in the original file. Notice that lines can be blank. 7. Search Terms: Write a function searchterms() that takes a search string as a parameter and returns an array of all search terms in the string. Every token in the string is considered a search term, except for tokens wrapped in double quotation marks: these phrases should be treated as a single search term. You may assume that all tokens in the string are separated by exactly one space and that no search string has an odd number of double quotation marks that is, all beginning quotation marks have a matching set of ending quotation marks. For example, searchterms("curious george") returns {"curious", "george"} and searchterms( "The Man with the Yellow Hat" ) returns {"The Man with the Yellow Hat"}. 8. Line sums: Write a PHP function called linesum that accepts one integer and a filename as a parameter and returns the sum of the integers on that line number. For example, you may have a file named sums.txt that contains the following data: 5 15 10 20 25 50 200 50 60 75 100 A call to linesum( "sums.txt", 2) returns 25, and a call to linesum("sums.txt", 5) returns 200. 9. GCD and Euclid s Algorithm: Write a function named gcd that accepts two integers as parameters and returns the greatest common divisor (GCD) of the two numbers. The greatest common divisor of two integers a and b is the largest integer that is a factor of both a and

Error! No text of specified style in document. 3 b. The GCD of any number and 1 is 1, and the GCD of any number and 0 is that number. One efficient way to compute the GCD is to use Euclid's algorithm, which states the following: gcd(a, b) = gcd(b, a % b) gcd(a, 0) = Absolute value of a For example: gcd(24, 84) returns 12, gcd(105, 45) returns 15, and gcd(0, 8) returns 8. 10. Inside Out: Write a PHP function called insideout() that will accept an array and return it with its innermost elements swapped with its outer most elements. For example, calling insideout(array(1, 2, 2, 1)) would return the array: (2, 1, 1, 2). Similarly, the method call insideout(array("everyone", "says", "Kelly", "is", "REALLY", "awesome")) would result in: ("Kelly", "says", "Everyone", "awesome", "REALLY", "is"). The array should only be altered if it has an even number of elements. Return the array passed in if this is not the case. 11. Emailidate: Create a function called emailidate() that validates email addresses. The function takes as a parameter a string of email addresses delimited by commas. It should return an array of valid email addresses. An email address is considered valid if it is of the form a@b.c, where a, b, and c are non-empty strings. Invalid email addresses are ignored. If none of the email addresses are valid, the function should return FALSE. 12. University Info: Write a function universityinfo() which accepts a university name as a parameter and returns an array containing information about the given university. The array should have a "location" key, whose value is the university's location, a "founded" key, whose value is the founding date of the university, and a "name" key containing the name of the university. The information about the university is stored in a text file called unidata.txt and has the following format: University Name University Location Date Founded University Name University Location Date Founded You may assume any university name passed to universityinfo() can be found in the text file and that all universities in the text file have all required information. This function should be case insensitive, i.e. universityinfo("university OF washington") should return the same results as universityinfo("university of Washington"). Example call: $info = universityinfo("university of Washington");

4 Exercises echo $info[ name ]; //outputs "University of Washington" echo $info[ location ]; //outputs "Seattle, Washinton" echo $info[ founded ]; //outputs "1861" 13. Folder Crawler: Write a PHP function called foldercrawler() that takes a full path to a folder as a parameter and outputs the HTML for an unordered list of all the files in that folder. The filenames should link to the files themselves, and before every filename you should display an appropriate icon based on the file extension. All icon images are in a folder called icons located in the root directory of the website and each icon is saved as a gif file named <extension>.gif ; for example, the icon for an HTML file is called html.gif. You may assume that every file extension has an icon. 14. Welcome Message: The following webpage has a form prompting the user for his or her name. Edit the HTML and use embedded PHP to modify the following webpage to display a welcome message of the form, Hello, <name>! if the user types his or her name into the text box and presses Enter. The form should send the submission as a POST request and the welcome message should be displayed in as a level one heading above the form. <!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>welcome to my page!</title> </head> <body> <p> Enter your name: <br /> <input type="text" /> <input type="submit" value="enter" /> </p> </body> </html> 15. Welcome Message, revisited: Modify your solution to the Welcome Message exercise to remember the last person who visited the webpage. Save the person s submitted name in a flat file called visitor.txt and read the first line of this text file to retrieve the name when the page loads. You should overwrite this name every time someone submits a name to the form. You can assume there is always a name in the text file and you can assume the submitted name is not blank. You should add the following paragraph after the prompt for the user s name. Replace [NAME] with the name of the last visitor. <p> The last person who visited my website was [NAME]. </p> 16. Intro to Phishing: The following HTML is a snippet of a website trying to masquerade as Google. It asks for the user s name and credit card number in addition to the search query.

Error! No text of specified style in document. 5 Write a PHP program called phish.php that processes the form submission. This program should save the name and credit card number to a text file called suckers.txt. (The information can be saved in any readable format of your choosing.) The program should then redirect the user to the actual Google search results page for the search query they typed in. You may find the PHP header() function to be useful in this task. Hint: As described in the beginning of Chapter 6, the URL for a Google search results page is of the form http://www.google.com/search?q=<search value>. <h1>google.com!</h1> <p> Welcome to Google.com <br /> Google now requires your full name and credit card number before you are allowed to make a search. </p> <form action="phish.php" method="post"> <fieldset> Name: <input type="text" name="name" /><br /> Credit Card Number: <input type="text" name="ccn" /><br /> Search Query: <input type="text" name="query" /> <br /> <input type="submit" value="i m pheeling lucky" /> </fieldset> </form> Disclaimer: We do not in any way condone or encourage phishing attacks! This is just a silly exercise written in jest. 17. Image Gallery Search: The following HTML snippet is the skeleton of a simple search page for an image gallery. The gallery stores all of its images in a directory called images. Write a PHP program called search.php to implement the searching feature. An image is considered a match to the search string if the name of the image contains the entirety of the search string. For example, a query of tea might match tea.jpg or steamboat.jpg. The search should be case-insensitive and you should eliminate the whitespace surrounding a query before processing it. You should output an unordered list of links to all matches. A blank query should return no results. You may assume there are only image files in the images directory. <h1>image Gallery Search<h1> <form action="search.php" method="get"> <fieldset> Type a query: <input type="text" name="query" /> <br /> <input type="submit" value="search" /> </fieldset> </form> 18. Image Gallery Search, revisited: Modify your solution to the Image Gallery Search exercise to account for a smarter search algorithm and a more appealing results page:

6 Exercises Instead of matching only image names that contain the exact search string, an image is considered a match if it contains any of the terms in the search string. You should treat phrases wrapped in quotation marks as a single term. You may find it useful to use the searchterm() function written in the Search Terms exercise. Instead of outputting a list of matched image names, output thumbnails of the matched images that link to the full-sized image. The thumbnails should be 100px in height. 19. Contact Form: Create a valid web page called contact.html that contains a form to let users send you a simple message via email. The form should contain a text field for the "from" email address, a text field for the subject text of the email, and a textarea for the body of the message. You should also write a page called send.php to process the email submission. The code that you will need to actually send the message is PHP's mail() function: bool mail($to, $subject, $message, $additional_headers); The additional_headers parameter can be used to specify the from address, and it should be of the form "From: <email>" You may assume that the email address entered is a valid email address. 20. Contact Form, revisited: Modify your solution to contact.html to include the following features: Use the function from the Emailidate exercise to validate the from address entered by the user. If the email address is invalid, display a message saying such and do not send the message. If the email address is valid, send the message and display a confirmation message that the email was sent. You should also send a confirmation email back to the sender of the message, repeating the message that was sent.