PHP Programming.

Slides:



Advertisements
Similar presentations
» PHP arrays are lists of values stored in key-value pairs. » Uses of arrays: Many built-in PHP environment variables. Database functions use arrays.
Advertisements

File Management in C. What is a File? A file is a collection of related data that a computers treats as a single unit. Computers store files to secondary.
Using GET data within a IF Statement. If ($GETCom === ‘home’) { echo ’They Match’; } $GETCom = $_GET[‘com’]; If the data stored in the variable ($GETCom)
CHAPTER 11 FILE INPUT & OUTPUT Introduction to Computer Science Using Ruby (c) 2012 Ophir Frieder et al.
BITS Pilani, Pilani Campus TA C252 Computer Programming - II Vikas Singh File Handling.
File Management in C. A file is a collection of related data that a computers treats as a single unit. File is a collection of data stored permanently.
V 1.0 OE NIK 2013 PHP+SQL 4. File handling basics File-based "database" File-based guestbook 1.
More on PHP Coding Lab no. 6 Advance Database Management System.
Files Organisation sequential files. Readings u Schneider Chapter 8 u Shelly Cashman to 9.14; to 9.11 u Meyer to 2-37; 1995.
FILES Files types and operations. Files Files are used to store data Data can be Text (ASCII only: 0  127) Binary (Full range: 0  256) Each file resides.
A simple PHP application We are going to develop a simple PHP application with a Web interface. The user enters two numbers and the application returns.
2 $ command Command Line Options ls –a –l hello hi Command Arguments.
PHP Programming. Topics Background and History of PHP Installation Comments in PHP Variables Conditions Loops Functions File Handling Database Handling.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Intermediate PHP (2) File Input/Output & User Defined Functions.
(c) Manzur Ashraf, Short course, KFUPM PHP & MySQL 1 Basic PHP Class 2.
INTERNET APPLICATION DEVELOPMENT For More visit:
Lecture 6 – Form processing (Part 1) SFDV3011 – Advanced Web Development 1.
Applications with Random File Access CHAPTER 8. C.13 1 Where am I on the Binary File? » While a binary file is processed, it is a need to know current.
1 Homework Introduction to HW7 –Complexity similar to HW6 –Don’t wait until last minute to start on it File Access will be needed in HW8.
PHP - Basic Language Constructs CSCI 297 Scripting Languages - Day Two.
PHP2. PHP Form Handling The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input. Name: Age:
Introduction to Programming Using C Files. 2 Contents Files Working with files Sequential files Records.
Week 4 PHP H ypertext P reprocessor Reference : Official Site :
Storing and Retrieving Data
Outline Overview Opening a file How to create a file ? Closing a File Check End-of-file Reading a File Line by Line Reading a File Character by Character.
1 File Handling. 2 Storage seen so far All variables stored in memory Problem: the contents of memory are wiped out when the computer is powered off Example:
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Files & Directories.
LECTURE 4 Files, File open, Read, Write. File Upload - In this lecture we will teach you how to open, read, and close a file on the server. - PHP Open.
8 th Semester, Batch 2008 Department Of Computer Science SSUET.
Lecture 8a: File I/O BJ Furman 21MAR2011. Learning Objectives Explain what is meant by a data stream Explain the concept of a ‘file’ Open and close files.
Using Text Files in Excel File I/O Methods. Working With Text Files A file can be accessed in any of three ways: –Sequential access: By far the most common.
Artificial Intelligence Lecture No. 26 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Shell Scripting – Putting it All Together. Agenda Escaping Characters Wildcards Redirecting Output Chaining and Conditional Chaining Unnamed and Named.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
GAME203 – C Files stdio.h C standard Input/Output “getchar()”
CSC 405: Web Application Engineering II5.1 Web programming using PHP What have we learnt? What have we learnt? Motivation for validating user input (form.
1 CSC103: Introduction to Computer and Programming Lecture No 28.
1 CSC103: Introduction to Computer and Programming Lecture No 27.
Learners Support Publications Working with Files.
Files A collection of related data treated as a unit. Two types Text
Web Page Designing With Dreamweaver MX\Session 1\1 of 9 Session 3 PHP Advanced.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic properties and characteristics of external files ❏ To.
PHP Overview. What is PHP Widely available scripting language Free Alternative to Microsoft’s ASP Runs on the Web Server; not in the browser Example:
C Programming Day 2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/LA07/003 Version No. 1.0 Union –mechanism to create user defined data types.
Programming for the Web Data Structure Writing to a file Dónal Mulligan BSc MA
PHP: Further Skills 02 By Trevor Adams. Topics covered Persistence What is it? Why do we need it? Basic Persistence Hidden form fields Query strings Cookies.
PHP File Handling. Opening a file Fopen(filename,mode) Closing a file Fclose(filename)
Silberschatz and Galvin  C Programming Language Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University College of Education.
Chapter 7 Text Input/Output Objectives
CGS 3066: Web Programming and Design Spring 2016
RECURSION Recursion is a process where a function calls itself. main()
Chapter 22 – part a Stream refer to any source of input or any destination for output. Many small programs, obtain all their input from one stream usually.
Chapter 7 Text Input/Output Objectives
File Access (7.5) CSE 2031 Fall July 2018.
CS111 Computer Programming
CSE1320 Files in C Dr. Sajib Datta
File Input/Output.
CSE1320 Files in C Dr. Sajib Datta
CSE1320 Files in C Dr. Sajib Datta
File I/O in C Lecture 7 Narrator: Lecture 7: File I/O in C.
File Handling.
Functions continued.
Reading from and Writing to Files
FILE handeling.
ETE 132 Lecture 8 By Munirul Haque.
EECE.2160 ECE Application Programming
Reading from and Writing to Files
Programming Techniques :: File Handling
Presentation transcript:

PHP Programming

Topics Functions File Handling

Functions and Parameters PHP functions need to be defined with key word function It can have zero or more values (parameters) Functions may or may not return values If a function need to return value, the last statement of the function should be return return value;

Functions Parameter less function <?php function sayHi() { echo “hi”; } ?> This can be called as <?php sayHi(); ?> in the program

Functions Parameterized function <?php function greet($name) { echo “Hello “ . $name; } ?> This can be called <?php greet(‘Ram’);?> This gives an output Hello Ram

Functions Function returning value <?php function add($a,$b) { return ($a + $b); } ?> When called like <?php echo add(1,2);?> we will get an output 3 in the browser.

File Handling This involves 5 tasks Opening a file Reading data from a file Displaying the read data Writing contents to another file Closing a file

Opening a file $fp = fopen(‘filename’,’mode’); Eg $fp = fopen(‘c:\abc.txt’,’r’); This opens a file abc.txt in read only mode Available modes: r – read only w – write only w+ - read write A – append – adding to the end

Reading a file Several methods are available fread(filepointer,no of bytes to read) fgetc(filepointer) – Reads character by character fgets(filepointer) – Reads line by line The read content can be stored in a variable $data = fread($fp,10) – this reads 10 characters from file pointed by file pointer $fp and stores in $data If we want to read characters till end, we need to use a loop with condition checking for End of File

Writing to file We can use echo $data, to print the contents read from the file to browser Or we can open another file in write mode and put the contents to that file using either of these methods fwrite(filepoiner,data); fputc(filepointer,char); - writes character by character fputs(filepointer,line); - writes line by line Eg - fwrite($fpw,$data);

Closing a file feof(fp) – Checks for end of file. Returns –1 if EOF is reached. Otherwise returns 0 To close a file use fclose(filepointer) method Eg. fclose($fp); This closes the file pointed by $fp.