Slide 1 PHP Predefined Functions ITWA113. Murach’s ASP.NET 3.5/C#, C1© 2008, Mike Murach & Associates, Inc. Slide 2 PHP Predefined Functions Objectives.

Slides:



Advertisements
Similar presentations
PHP: Date() Function The PHP date() function formats a timestamp to a more readable date and time.
Advertisements

LIS651 lecture 3 functions and arrays Thomas Krichel
Session 3BBK P1 Module05-May-2007 : [‹#›] Date Manipulation.
C Characters & Strings Character Review Character Handling Library Initialization String Conversion Functions String Handling Library Standard Input/Output.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
Session 8 JavaScript/Jscript: Objects Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
ITC 240: Web Application Programming SUBHASH PRAJAPATI 04/14/15.
Display a 12-Month Calendar CS-2301 D-term Programming Assignment #2 12-Month Calendar CS-2301 System Programming C-term 2009 (Slides include materials.
Databases Lab 5 Further Select Statements. Functions in SQL There are many types of functions provided. The ones that are used most are: –Date and Time.
Intermediate PHP & MySQL
IS 1181 IS 118 Introduction to Development Tools Chapter 4 String Manipulation and Regular Expressions.
Operations & Strings CSCI 116 Web Programming I. 2 Arithmetic Operators Arithmetic operators are used to perform mathematical calculations.
Assignment #2, 12- month Calendar CS-2301, B-Term Programming Assignment #2 12-Month Calendar CS-2301, System Programming for Non-Majors (Slides.
04/09/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Practical PHP IDIA Spring 2012 Bridget M. Blodgett.
Strings PART II STRING$ AND SPACE$. Create strings of specified number String$ creates string of specified character Space$ creates string of spaces Example:
Using Object-Oriented JavaScript CST 200- JavaScript 4 –
Website Development & Management More PHP Fundamentals CIT Fall Instructor: John Seydel, Ph.D.
Outline o What is String ? o Basic String o Using String As Arrays o Transforming String o Comparing Strings o Searching Strings o Matching Against Mask.
Lists in Python.
School of Computing and Information Systems CS 371 Web Application Programming PHP - Basics Serving up web pages.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Includes and Dates.
Nael Alian Introduction to PHP
Writing Web Pages By Shyam Gurram. Agenda Writing Web Pages Delimiting PHP Program Units. Displaying Output to Web Pages Putting Comments in PHP Programs.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
PHP Controlling Program Flow Mohammed M. Hassoun 2012.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
Computer Science 101 Introduction to Programming.
PHP Strings. Outline o String Variables In PHP o The Most Used Functions In PHP o Arrays Functions o Transforming String o Comparing Strings o Searching.
Introduction to PHP A user navigates in her browser to a page that ends with a.php extension The request is sent to a web server, which directs the request.
VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.
PHP2. PHP Form Handling The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input. Name: Age:
Web Database Programming Week 3 PHP (2). Functions Group related statements together to serve “a” specific purpose –Avoid duplicated code –Easy maintenance.
Class 2Intro to Databases Goals of this class Include & Require in PHP Generating Random Numbers in PHP Arrays – Numerically Indexed and Associative Program.
Oracle 11g: SQL Chapter 10 Selected Single-Row Functions.
PHP: A RRAYS, S TRINGS, AND F ILES CSCI 297 Scripting Languages - Day Three.
Introduction to PHP Advanced Database System Lab no.1.
What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server PHP supports.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
1 Microsoft® Visual Basic®.NET Language # 1. 2 Variable Declaring Variable Dim {VariableName} As {Type} Dim {VariableName} As {Type} = {value} Example:
SQL Functions. SQL functions are built into Oracle Database and are available for use in various appropriate SQL statements. These functions are use full.
1 STRINGS String data type Basic operations on strings String functions String procedures.
ECA 225 Applied Interactive Programming ECA 225 Applied Online Programming javascript dates.
1 Chapter 3 – Handling Strings and Arrays spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
SESSIONS 27/2/12 Lecture 8. ? Operator Similar to the if statement but returns a value derived from one of two expressions by a colon. Syntax: (expression)
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
Basic Scripting & Variables Yasar Hussain Malik - NISTE.
JavaScript: Objects 1 © by Pearson Education, Inc. All Rights Reserved.
Working with Date and Time ISYS 475. How PHP processes date and time? Traditional way: – Timestamp Newer and object oriented way: – DateTime class.
1 Arrays and Pointers The name of an array is a pointer constant to the first element. Because the array’s name is a pointer constant, its value cannot.
Web Page Designing With Dreamweaver MX\Session 1\1 of 9 Session 3 PHP Advanced.
PRÁCE S ČASEM V PHP. DATE  string date ( string $format [, int $timest amp = time() ] )  echo date('l jS \of F Y h:i:s A');  Monday 8th of August 2005.
Built-in Functions.
Open Source Server Side Scripting MySQL Functions
Variables, Expressions, and IO
Formatting Output.
© 2015, Mike Murach & Associates, Inc.
BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES
PHP.
VBScript Session 10.
String functions
Data Types and Expressions
Web Programming Language
php.ini (in C:\xampp\php\) date.timezone = Asia/Taipei
Advanced Concepts and AJAX
String functions
Presentation transcript:

Slide 1 PHP Predefined Functions ITWA113

Murach’s ASP.NET 3.5/C#, C1© 2008, Mike Murach & Associates, Inc. Slide 2 PHP Predefined Functions Objectives To know how to include separate PHP code in the main page for code enhancement. To be familiar with the use of common predefined function such as define, include, and require. To use different available mathematical function for manipulating numbers. To use number_format() function for number readability purpose. To apply different function for Array Manipulation using the function unset(), explode(), and implode(). To manipulate string data using PHP string manipulation function. To manipulate date with format using date function and date format available.

Slide 3 PHP Predefined Functions Using Constant define() functions used to declare constants. A constant can only be assigned a scalar value, like a string or a number. A constant’s value cannot be changed. Syntax: define(‘NAME’,’value’); Example:Output:

Slide 4 PHP Predefined Functions Including Files You can separate your PHP file and embed it to your html by using PHP include functions. Syntax: include(“file”); Include functionsDescription include Includes and evaluates the specified file. Generate a warning on failure message if file not found. require Performs the same way as the include function. Generate a fatal error message if file not found stopping the script at that point. include_once Same as include function except it includes the file only once. require_once Same as require function except it includes the file only once.

Slide 5 PHP Predefined Functions Including Files Most of the developers used include functions for their header and footer. Also some use this to write their database connection and so on. You may write the file with an extension name of.inc rather than.php to serve as a fragment of your program code. In some scripts, a file might be included more than once, causing function redefinitions, variable reassignments, and other possible problems. Syntax: include(“filename.inc”); include_once(“filename.inc”); require(“filename.inc”); require_once(“filename.inc”);

Slide 6 PHP Predefined Functions Including Files : include() function (file not found) Example: Output:

Slide 7 PHP Predefined Functions Including Files: require() function (file not found) Example: Output:

Slide 8 PHP Predefined Functions Including Files: include() function (file exists) Example: Same output using require function header.inc Output:

Slide 9 PHP Predefined Functions Mathematical Function: rand() function - used to generate random integers - syntax int rand(void) int rand(int $min, int $max) ceil() function - returns the next highest integer by rounding the value upwards - syntax float ceil(float $value) floor() function - returns the next lowest integer by rounding the value downwards - syntax float floor(float $value)

Slide 10 PHP Predefined Functions Mathematical Function: min() function - Return the smallest value - syntax mixed min(array $values) mixed min(mixed $values1, mixed $values2[,mixed $...] ) max() function - Return the highest value - syntax mixed max(array $values) mixed max(mixed $values1, mixed $values2[,mixed $...])

Slide 11 PHP Predefined Functions Mathematical Function: rand(), ceil(), floor(), min(), max() Output: Example:

Slide 12 PHP Predefined Functions Mathematical Function: number_format() function - Format a number with grouped thousand - syntax string number_format ( float $number [, int $decimals = 0 ] ) string number_format ( float $number, int $decimals = 0, string $dec_point = '.', string $thousands_sep = ',' )

Slide 13 PHP Predefined Functions Mathematical Function: number_format function Output: Example:

Slide 14 PHP Predefined Functions Function for Array Manipulation: unset function - destroys the specified variable - syntax: void unset ( mixed $var [, mixed $... ] ) explode function - split a string by string - syntax: array explode ( string $delimiter, string $string [, int $limit ] ) implode function - join array elements to form a string - syntax: string implode ( string $glue, array $pieces ) string implode ( array $pieces )

Slide 15 PHP Predefined Functions Function for Array Manipulation: unset(), explode(), implode() Output: Example:

Slide 16 PHP Predefined Functions Function for String Manipulation: strlen function - return the value length of a string - syntax: int strlen (string $string) strpos function - find the position of the first occurrence of a substring in a given string - syntax: int strpos ( string $haystack, mixed $needle [, int $offset = 0 ] ) strrev function - reverse a given string - syntax: string strrev ( string $string )

Slide 17 PHP Predefined Functions Function for String Manipulation: strtolower function - converts string to lowercase - syntax: string strtolower ( string $str ) strtoupper function - converts string to uppercase - syntax: string strtoupper ( string $str ) substr function - returns part of a given string - syntax: string substr ( string $string, int $start [, int $length ] )

Slide 18 PHP Predefined Functions Function for String Manipulation: strlen(), strpos(), strrev(), strtolower(), strtoupper(), substr() Output: Example:

Slide 19 PHP Predefined Functions Function for String Manipulation: ucfirst() function - Make a string’s first character uppercase - syntax: string ucfirst( string $str ) ucwords() function - converts string to uppercase - syntax: string ucwords ( string $str ) trim() function - stripped white spaces or other characters from the beginning and end of a string. - syntax: string trim ( string $str [, string $charlist ] )

Slide 20 PHP Predefined Functions Function for String Manipulation: ltrim() function - strip white spaces or other characters from the beginning of a string. - syntax: string ltrim ( string $str [, string $charlist ] ) rtrim() function - strip white spaces or other characters from the end of a string. - syntax: string rtrim ( string $str [, string $charlist ] ) strip_tags() function - strip HTML and PHP tags from a string. - syntax: string strip_tags ( string $str [, string $allowable_tags ] )

Slide 21 PHP Predefined Functions Function for String Manipulation: ucfirst(), ucwords(), trim(), ltrim(), rtrim(), strip_tags() Output: Example:

Slide 22 PHP Predefined Functions Function for String Manipulation: ucfirst(), ucwords(), trim(), ltrim(), rtrim(), strip_tags() Output: Example:

Slide 23 PHP Predefined Functions Date Manipulation: date() Function - used to format a local time or date - returns a string formatted according to the given format string. - syntax: string date ( string $format [, int $timestamp = time() ] ) Format character DescriptionExample returned values DAY d Day of the month, 2 digits with leading zeros01 to 31 D A textual representation of a day, three lettersMon through Sun j Day of the month without leading zeros1 to 31 l A full textual representation of the day of the week Sunday through Saturday N ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0) 1 (for Monday) through 7 (for Sunday)

Slide 24 PHP Predefined Functions Date Manipulation: date() Function Format character DescriptionExample returned values S English ordinal suffix for the day of the month, 2 characters st, nd, rd or th. Works well with j w Numeric representation of the day of the week0 (for Sunday) through 6 (for Saturday) z The day of the year (starting from 0)0 through 365 WEEK W ISO-8601 week number of year, weeks starting on Monday Example: 42 (the 42nd week in the year)

Slide 25 PHP Predefined Functions Date Manipulation: date() Function Format character DescriptionExample returned values MONTH F A full textual representation of a month, such as January or March January through December m Numeric representation of a month, with leading zeros 01 through 12 M A short textual representation of a month, three letters Jan through Dec n Numeric representation of a month, without leading zeros 1 through 12 t Number of days in the given month28 through 31

Slide 26 PHP Predefined Functions Date Manipulation: date() Function Format character DescriptionExample returned values YEAR L Whether it's a leap year1 if it is a leap year, 0 otherwise. o ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. Examples: 1999 or 2003 Y A full numeric representation of a year, 4 digitsExamples: 1999 or 2003 y A two digit representation of a yearExamples: 99 or 03

Slide 27 PHP Predefined Functions Date Manipulation: date() Function Format character DescriptionExample returned values TIME a Lowercase Ante meridiem and Post meridiemam or pm A Uppercase Ante meridiem and Post meridiemAM or PM B Swatch Internet time000 through 999 g 12-hour format of an hour without leading zeros1 through 12 G 24-hour format of an hour without leading zeros0 through 23 h 12-hour format of an hour with leading zeros01 through 12 H 24-hour format of an hour with leading zeros00 through 23 i Minutes with leading zeros00 to 59 s Seconds, with leading zeros00 through 59 u MicrosecondsExample:

Slide 28 PHP Predefined Functions Date Manipulation: date() Function Format character DescriptionExample returned values TIMEZONE e Timezone identifierExamples: UTC, GMT, Atlantic/Azores I Whether or not the date is in daylight saving time 1 if Daylight Saving Time, 0 otherwise. O Difference to Greenwich time (GMT) in hoursExample: P Difference to Greenwich time (GMT) with colon between hours and minutes Example: +02:00 T Timezone abbreviationExamples: EST, MDT... Z Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive through 50400

Slide 29 PHP Predefined Functions Date Manipulation: date() Function Format character DescriptionExample returned values FULL DATE/TIME c ISO 8601 date T15:19:21+00:00 r » RFC 2822 formatted dateExample: Thu, 21 Dec :01: U Seconds since the Unix Epoch (January :00:00 GMT) See also time()

Slide 30 PHP Predefined Functions Date Manipulation: date() Function Output: Example:

Slide 31 PHP Predefined Functions Date Manipulation: mktime() function - get the unix timestamp (January 1, 1970) for a given date. (with strict notice) - same as time() function (without strict notice) - syntax: int mktime ([ int $hour = date("H") [, int $minute = date("i") [, int $second = date("s") [, int $month = date("n") [, int $day = date("j") [, int $year = date("Y") [, int $is_dst = -1 ]]]]]]] )

Slide 32 PHP Predefined Functions Date Manipulation: strtotime() function - parse any English textual datetime description into a Unix timestamp - syntax: int strtotime ( string $time [, int $now = time() ] )