1 PHP Intro PHP Strings After this lecture, you should be able to: Manipulate and Output PHP Strings: Manipulate and Output PHP Strings: Single- or Double-quoted.

Slides:



Advertisements
Similar presentations
FORM VALIDATION Faheem Ahmed Khokhar. FORM VALIDATION Faheem Ahmed Khokhar.
Advertisements

Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
Chapter 7 Strings F To process strings using the String class, the StringBuffer class, and the StringTokenizer class. F To use the String class to process.
Chapter 7 Strings F Processing strings using the String class, the StringBuffer class, and the StringTokenizer class. F Use the String class to process.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Master Manipulator perl Perl is.
Introduction to Perl Bioinformatics. What is Perl? Practical Extraction and Report Language A scripting language Components an interpreter scripts: text.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
C. About the Crash Course Cover sufficient C for simple programs: variables and statements control functions arrays and strings pointers Slides and captured.
Tutorial 14 Working with Forms and Regular Expressions.
Validating user input Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
Chapter 7. 2 Objectives You should be able to describe: The string Class Character Manipulation Methods Exception Handling Input Data Validation Namespaces.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
1 CS428 Web Engineering Lecture 19 Data Types (PHP - II)
XP Tutorial 14 New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Last Updated March 2006 Slide 1 Regular Expressions.
Strings and Arrays. String Is a sequence of characters. Example: “hello”, “how are you?”, “123”,and are all valid string values.
Server-Side Validation Jayden Bryant. What is Server-Side Validation?  Validation of form input done on the server, not the web browser program //Validate.
Tutorial 14 Working with Forms and Regular Expressions.
COP 3813 Intro to Internet Computing Prof. Roy Levow PHP.
Sys.Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 18: Regular Expressions in PHP.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
PHP Using Strings 1. Replacing substrings (replace certain parts of a document template; ex with client’s name etc) mixed str_replace (mixed $needle,
ASP.NET Programming with C# and SQL Server First Edition Chapter 5 Manipulating Strings with C#
CIS 451: Regular Expressions Dr. Ralph D. Westfall January, 2009.
Finding the needle(s) in the textual haystack
Strings CS303E: Elements of Computers and Programming.
Strings in PHP Working with Text in PHP Strings and String Functions Mario Peshev Technical Trainer Software University
Chapter 7 Strings  Use the String class to process fixed strings.  Use the StringBuffer class to process flexible strings.  Use the StringTokenizer.
PHP Conditional Statements Conditional statements in PHP are used to perform different actions based on different conditions. Conditional Statements Very.
13/2/12 Lecture 6. Functions 2 types: – Built in functions – Custom defined functions Functions minimize the amount of repetition of code. function consists.
Programming in Perl regular expressions and m,s operators Peter Verhás January 2002.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2015, Fred McClurg, All Rights.
An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting.
PHP with Regular Expressions Web Technologies Computing Science Thompson Rivers University.
Comments in PHP In PHP, we use // to make a singleline comment or /* and */ to make a large comment block. Comment is a part of your PHP code that will.
Regular Expressions in PHP. Supported RE’s The most important set of regex functions start with preg. These functions are a PHP wrapper around the PCRE.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved. 1.
12. Regular Expressions. 2 Motto: I don't play accurately-any one can play accurately- but I play with wonderful expression. As far as the piano is concerned,
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
PHP’s Regular Expression Functions (Perl Compatible) Examples taken from: Beginning PHP 5 and MySQL 5 From Novice to Professional.
Powerpoint Templates Page 1 Powerpoint Templates GROUP 8:REGULAR EXPRESSION GURU BESAR: PN. SARINA SULAIMAN CIKGU-CIKGU: 1.CIKGU NENI 2.CIKGU
Computer Programming for Biologists Class 6 Nov 21 th, 2014 Karsten Hokamp
CSC 2720 Building Web Applications PHP PERL-Compatible Regular Expressions.
1 Microsoft® Visual Basic®.NET Language # 1. 2 Variable Declaring Variable Dim {VariableName} As {Type} Dim {VariableName} As {Type} = {value} Example:
1 Lecture 9 Shell Programming – Command substitution Regular expressions and grep Use of exit, for loop and expr commands COP 3353 Introduction to UNIX.
C++ String Class nalhareqi©2012. string u The string is any sequence of characters u To use strings, you need to include the header u The string is one.
Department of Electrical and Computer Engineering Introduction to Perl By Hector M Lugo-Cordero August 26, 2008.
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.
Validation using Regular Expressions. Regular Expression Instead of asking if user input has some particular value, sometimes you want to know if it follows.
Unit 11 –Reglar Expressions Instructor: Brent Presley.
Regular Expressions /^Hel{2}o\s*World\n$/ SoftUni Team Technical Trainers Software University
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
XP Tutorial 7 New Perspectives on JavaScript, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Interpolation Variable Interpolation, Backslash Interpolation.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
A FIRST BOOK OF C++ CHAPTER 14 THE STRING CLASS AND EXCEPTION HANDLING.
Variable Variables A variable variable has as its value the name of another variable without $ prefix E.g., if we have $addr, might have a statement $tmp.
The Scripting Programming Language
CSE 154 LECTURE 16: FILE I/O; FUNCTIONS. Query strings and parameters URL?name=value&name=value...
Lesson 4 String Manipulation. Lesson 4 In many applications you will need to do some kind of manipulation or parsing of strings, whether you are Attempting.
C++ Memory Management – Homework Exercises
Chapter 19 PHP Part II Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
SAS in Data Cleaning.
Selenium WebDriver Web Test Tool Training
Embedded PHP in HTML 5 & Strings in PHP
Validation using Regular Expressions
awk- An Advanced Filter
Presentation transcript:

1 PHP Intro PHP Strings After this lecture, you should be able to: Manipulate and Output PHP Strings: Manipulate and Output PHP Strings: Single- or Double-quoted strings Single- or Double-quoted strings String Conversion String Conversion String Functions String Functions

2 PHP String PHP Strings A string can be single- or double-quoted. A string can be single- or double-quoted. An extensive set of functions for strings are provided: An extensive set of functions for strings are provided: Manipulation with a regular expression, Manipulation with a regular expression, Conversion between a string and an array, Conversion between a string and an array, Outputing by echo(), print(), printf(), and print_r(), and Outputing by echo(), print(), printf(), and print_r(), and Others Others

3 PHP String Single-Quoted String No evaluation occurs for a single-quoted string. $age = 20; echo 'I am $age.\n'; echo ''Single''; echo '\”Double\”'; echo '”Double”'; echo $age >= 18 ? 'OK' : ''; I am $age.\n (illegal) \“Double\” “Double” OK

4 PHP String Double-Quoted String $age = 20; echo “I am $age.\n”; echo “'Single'\n”; echo “\”Double\”\n”; echo “”Double””; echo $age >= 18 ? “OK” : “”; Variables and escape sequences within a double-quoted string are evaluated or replaced. I am 20. 'Single' “Double” (illegal) OK

5 PHP String int strlen(string) $str = 'Hello'; $len = strlen($str); echo $len; Returns the length of string string. 5

6 PHP String int strpos(string1, string2) $str = 'My dog house.'; $position = strpos($str, 'dog'); echo $position; Returns the numeric position of string2 in string1. 3

7 PHP String int strpos($str1, $str2 ): Warning Returns false if $str2 is not a substring of $str1. Returns false if $str2 is not a substring of $str1. Returns 0 if $str2 is at the beginning of $str1, so using if(strpos($str1, $str2) == 0) could cause an unreliable result. Returns 0 if $str2 is at the beginning of $str1, so using if(strpos($str1, $str2) == 0) could cause an unreliable result. if(strpos($str1, $str2) === 0) may be used. if(strpos($str1, $str2) === 0) may be used.

8 PHP String string substr (string, start[, length] ) Substring $str = “My dog.”; $str2 = substr($str, 3); echo $str2 $str3 = substr($str1, 3, 2); echo $str3 dog. do Returns the string present in string starting from location start until end of string.

9 PHP String array explode(delim, string): $str = “Kelley Engineering Center”; $arr = explode(" ", $str); echo “$arr[0]\n$arr[1]\n$arr[2]\n”; Creates an array of the substrings in string, separated by delim. Kelley Engineering Center

10 PHP String string implode(delim, array): $arr = array('S10', 'Wolf', '20'); $string = implode('|', $arr); echo $string Creates a string out of the elements in array, connected by delim. S10|Wolf|20

11 PHP String int ereg(pattern, string[, array]): Pattern Matching I ereg('boy', 'cowboys'); ereg('^boy', 'cowboys'); ereg('^cow', 'cowboys'); ereg('cow$', 'cowboys'); ereg('boys$', 'cowboys'); Tests whether or not string matches regular expression pattern. truefalsetruefalsetrue This function has been DEPRECATED as of PHP preg_match() is an alternative.

12 PHP String Meta Characters for a Regular Expression ^ - start of line, or negation of characters characters $ - end of line. - any character [] – range, or set of characters () – grouping * - any number of times + - at least once ? - exactly once {n, m} – match n through m occurrences The following meta characters can be used in a regular expression. regular expression.

13 PHP String int ereg(pattern, string[, array]): Pattern Matching II ereg('.*', 'cowboys'); ereg(' ', 'cowboys'); ereg('c.*s', 'cowboys'); ereg('c.*s', 'cowgirls'); ereg('c.*s', 'tomboys'); ereg('^a*b*$', 'aaabb'); ereg('^a*b*$', 'bbbb'); ereg('^a*b*$', 'ccbbb'); ereg('^a+b*$', 'aabbb'); ereg('^a+b*$', 'bbb'); Wild card characters. truetruetruetruefalsetruetruefalsetruefalse

14 PHP String int ereg(pattern, string[, array]): Pattern Matching III ereg('^[a-z]*$', 'cowboy'); ereg('^[a-z]*$', 'cowboy123'); ereg('^[a-z]*[0-9]*$', 'cowboy123'); ereg('^[a-z]{6}$', 'cowboy'); ereg('^[a-z]{4}$', 'cowboy'); ereg('^[bcowy]*$', 'cowboy'); ereg('^[^0-9]$', 'a'); Specifying a range or set of valid characters. truefalsetruetruefalsetruetrue

15 PHP String int ereg(pattern, string[, array]): Extracting Substrings $ = $ , $arr); echo “User: $arr[1]\n”; echo “Host: $arr[2]\n”; echo “ $arr[0]\n”; User: pham Host: eecs.oregonstate.edu Retrieving text in groups.

16 PHP String Meta Characters for a Regular Expression ^ - start of line, or negation of characters characters $ - end of line. - any character [] – range, or set of characters () – grouping * - any number of times + - at least once ? - exactly once {n, m} – match n through m occurrences The following meta characters can be used in a regular expression. regular expression.

17 Example: is_safe_int() <?php function is_safe_int($var) { $pattern = "/^0$|^[1-9][0-9]*$/"; if(preg_match($pattern, $var)) { return true; } else { return false; } ?>