String functions http://www.w3schools.com/php/php_ref_string.asp.

Slides:



Advertisements
Similar presentations
IntroductION to SERVER-SIDE WEB PROGRAMMING
Advertisements

Computer Science & Engineering 2111 Text Functions 1CSE 2111 Lecture-Text Functions.
Character String Manipulation. Overview Character string functions sscanf() function sprintf() function.
Strings CS240 Dick Steflik. What is a string A null terminated array of characters: char thisIsAString[10]; \0 The “\0” (null character)
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Characters and Strings.
Faculty of Sciences and Social Sciences HOPE PHP – Working with Files and Strings Stewart Blakeway FML 213
Lab Homework #3 PHP Overview (based on by Lisa Wise)
Data Manipulation & Regular Expressions CSCI 215.
Chapter 3 Manipulating Strings PHP Programming with MySQL 2nd Edition
Introduction to Oracle9i: SQL1 Selected Single-Row Functions.
Manipulating Strings. 2 Topics Manipulate strings Manipulate strings Parse strings Parse strings Compare strings Compare strings Handle form submissions.
Validating user input Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
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.
Manipulating Strings. Name of Book2 Objectives Manipulate strings Parse strings Compare strings Handle form submissions.
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
Strings and Arrays. String Is a sequence of characters. Example: “hello”, “how are you?”, “123”,and are all valid string values.
Strings IDIA 618 Spring 2013 Bridget M. Blodgett.
Lecture 12 PHP Basics Boriana Koleva Room: C54
Website Development & Management More PHP Fundamentals CIT Fall Instructor: John Seydel, Ph.D.
PHP Workshop ‹#› Data Manipulation & Regex. PHP Workshop ‹#› What..? Often in PHP we have to get data from files, or maybe through forms from a user.
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.
Chapter 3 Manipulating Strings PHP Programming with MySQL 2nd Edition
Manipulation Masterclass By the VB Gods. In this masterclass, we will learn how to use some of the string manipulation function such as Len, Right, Left,
PHP Controlling Program Flow Mohammed M. Hassoun 2012.
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL.
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.
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.
Strings in PHP Working with Text in PHP Strings and String Functions Mario Peshev Technical Trainer Software University
Web Database Programming Week 3 PHP (2). Functions Group related statements together to serve “a” specific purpose –Avoid duplicated code –Easy maintenance.
Oracle 11g: SQL Chapter 10 Selected Single-Row Functions.
Introduction to PHP Language Summary.
PHP: A RRAYS, S TRINGS, AND F ILES CSCI 297 Scripting Languages - Day Three.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
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.
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.
M275 Arab Open University Faculty of computer Studies M275 - Web Development using PHP and MySQL FALL
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.
8 1 String Manipulation CGI/Perl Programming By Diane Zak.
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.
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.
CSC 162 Visual Basic I Programming. String Functions LTrim( string ) –Removes leading spaces from the left side of string RTrim( string ) –Removes trailing.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 this week – last section on Friday. Assignment 4 is posted. Data mining: –Designing functions.
13/06/ Strings Left, Right and Trim. 213/06/2016 Learning Objectives Explain what the Left, Right and Trim functions do.
PHP Programming with MySQL Slide 5-1 CHAPTER 5 Manipulating Strings.
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.
String Methods Programming Guides.
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL
CS 371 Web Application Programming
C Characters and Strings
Server-Side Application and Data Management IT IS 3105 (Spring 2010)
PHP Hypertext Preprocessor
Introduction to Web programming
Chapter 3 Manipulating Strings PHP Programming with MySQL 2nd Edition Modified by Anita Philipp –Spring 2011.
PHP Function.
PHP.
Embedded PHP in HTML 5 & Strings in PHP
VBScript Session 10.
Data Manipulation & Regex
Web Programming Language
Topics Basic String Operations String Slicing
Introduction to Computer Science
Strings Adapted from Dr. Mary Eberlein, UT Austin.
Python Strings.
Topics Basic String Operations String Slicing
String functions
Strings Adapted from Dr. Mary Eberlein, UT Austin.
Topics Basic String Operations String Slicing
What We Want To Do User enters: Mary Smith
Presentation transcript:

String functions http://www.w3schools.com/php/php_ref_string.asp

String Length $len = strlen("Hello World"); //11 Returns the length of a string str_word_count() Count the number of words in a string $len = strlen("Hello World"); //11 $wcnt = str_word_count("Hello World"); //2

echo and print echo() Outputs strings print() Outputs a string printf() Outputs a formatted string sprintf() Writes a formatted string to a variable fprintf() Writes a formatted string to a specified output stream vprintf() vsprintf() vfprintf() number_format() Formats a number with grouped thousands

printf( ) <?php $num1= 3.141592654; echo "$num1<br/>"; printf("%f<br/>", $num1); printf("%.2f", $num1); // printf("%f<br/>%.2f", $num1, $num1); ?>

number_format() Price: NT$45,080 Number: 315 Total: NT$14,200,200.00 <?php $price= 45080; $num = 315; $tot = $price * $num; echo "Price: NT\$", number_format($price),"<br/>"; echo "Number: $num<br/>"; echo "Total: NT\$", number_format($tot, 2),"<br/>"; ?> Price: NT$45,080 Number: 315 Total: NT$14,200,200.00

Split & Join explode() Breaks a string into an array str_split() Splits a string into an array implode() Returns a string from the elements of an array join() Alias of implode()

explode( ) <?php $strW = "HTML, CSS, JavaScript, PHP"; $arrW = explode(", ",$strW); echo "<ul>"; for ($i=0;$i<count($arrW);$i++) echo "<li>$arrW[$i]</li>"; echo "</ul>"; ?>

implode( ) <?php $arrW = array("HTML", "CSS", "JavaScript", "PHP"); echo "[" . implode("] [",$arrW) . "]"; ?>

ltrim( ), rtrim( ), trim( ) Strips whitespace from both sides of a string chop() Alias of rtrim() rtrim() Strips whitespace from the right side of a string ltrim() Strips whitespace from the left side of a string <?php $hw = " Hello World! "; echo "\"$hw\"<br/>"; echo "ltrim: \"" . ltrim($hw) . "\"<br/>"; echo "rtrim: \"" . rtrim($hw) . "\"<br/>"; echo "trim: \"" . trim($hw) . "\"<br/>"; ?>

Replace, Convert str_replace() Replaces some characters in a string (case-sensitive) str_ireplace() Replaces some characters in a string (case-insensitive) substr_replace() Replaces a part of a string with another string str_pad() Pads a string to a new length str_repeat() Repeats a string a specified number of times str_shuffle() Randomly shuffles all characters in a string strrev() Reverses a string strtolower() Converts a string to lowercase letters strtoupper() Converts a string to uppercase letters ucfirst() Converts the first character of a string to uppercase ucwords() Converts the first character of each word in a string to uppercase addslashes() Returns a string with backslashes in front of predefined characters stripslashes() Unquotes a string quoted with addslashes()

Substring, Search strlen() Returns the length of a string substr() Returns a part of a string strstr() Finds the first occurrence of a string inside another string (case-sensitive) strchr() Finds the first occurrence of a string inside another string (alias of strstr()) stristr() Finds the first occurrence of a string inside another string (case-insensitive) strrchr() Finds the last occurrence of a string inside another string strpos() Returns the position of the first occurrence of a string inside another string (case-sensitive) stripos() Returns the position of the first occurrence of a string inside another string (case-insensitive) strrpos() Finds the position of the last occurrence of a string inside another string (case-sensitive) strripos() Finds the position of the last occurrence of a string inside another string (case-insensitive) strcmp() Compares two strings (case-sensitive) strcasecmp() Compares two strings (case-insensitive)

strpos( ) <?php $email = $_GET['mail']; //$_POST['mail'] if ($pos = strpos($email, '@')) { $user = substr($email,0,$pos); $server = substr($email, $pos+1); echo "E-mail: $email<br/>"; echo "User name: $user<br/>"; echo "Server: $server<br/>"; } else echo "<h2>Wrong E-mail!</h2>"; ?> If found, strpos() returns an integer. Otherwise, strpos() returns false; http://php.net/manual/en/function.strpos.php