SlideShare a Scribd company logo
Created by Nikul Shah
STRING FUNCTIONS
NIKUL SHAH 1
STRLEN()
• <?php
• echo strlen("Hello Nikul!");
• ?>
• /*output */
• 12
NIKUL SHAH 2
STR_WORD_COUNT()
• <?php
• echo str_word_count("Some people tend to forget that kindness and manners are free.");
• ?>
NIKUL SHAH 3
STRREV()
• <?php
• echo strrev("don't loss your hope.");
• ?>
NIKUL SHAH 4
STRPOS()
• strpos() function searches for a specific text within a string.
• If a match is found, the function returns the character position of the first match. If no
match is found, it will return FALSE.
• <?php
• echo strpos("Destiny works.", "works");
• ?>
NIKUL SHAH 5
STR_REPLACE ------ STRTR
• $search = array('A', 'B', 'C', 'D', 'E');
• $replace = array('B', 'C', 'D', 'E', 'F');
• $subject = 'A';
• $trans = array('A' => 'B','B'=>'C','C'=>'D','D'=>'E','E'=>'F');
• echo str_replace($search, $replace, $subject);
• echo "<br/>";
• echo strtr($subject,$trans);
NIKUL SHAH 6
• <?php
• echo str_replace("Nikul","Shah","Nik shah");
• ?>
NIKUL SHAH 7
ADDSLASHES()
• <?php
• $str=addslashes("today is 'monday'");
• echo "$str";
• ?>
• //output
• today is 'monday'
NIKUL SHAH 8
ADDCSLASHES()
• <?php
• $str=addcslashes("Nikul","k");
• echo "$str";
• ?>
• Be careful using addcslashes() on 0 (NULL), r (carriage return), n (newline), f (form feed),
t (tab) and v (vertical tab). In PHP, 0, r, n, t, f and v are predefined escape sequences.
NIKUL SHAH 9
CHR()
• The chr() function returns a character from the specified ASCII value.
• The ASCII value can be specified in decimal, octal, or hex values. Octal values are
defined by a leading 0, while hex values are defined by a leading 0x.
• <?php
$str = chr(43);
$str2 = chr(61);
echo("2 $str 2 $str2 4");
?>
NIKUL SHAH 10
EXPLODE()
• The explode() function breaks a string into an array.
• Note: The "separator" parameter cannot be an empty string.
• <?php
• $str="Hello my name is 'Nikul'";
• print_r (explode(" ",$str));
• print_r(explode(',',$str,0));
• ?>
• Using limits parameter it will returns no of elements.
• This function can not run on echo.
NIKUL SHAH 11
IMPLODE()
• implode() function returns a string from the elements of an array
• <?php
• $str =array('Hello','Nikul','How','are','You?');
• print_r(implode(",",$str));
• ?>.
NIKUL SHAH 12
JOIN()
• Joins array into string. Same as implode()
• <?php
• $im=array("nikul","Shah");
• echo (join(" ",$im));
• ?>
NIKUL SHAH 13
MD5()
• This function Calculates the MD5 hash of a string.
• <?php
• $im=array("nikul","Shah");
• echo md5(join(" ",$im));
• ?>
• 4994812ba7d125a30e2b9c04e7b7c014
NIKUL SHAH 14
NL2BR()
• Inserts HTML line breaks in front of each newline in a string
• <?php
• $n="Nikul nShah";
• echo nl2br($n);
• ?>
NIKUL SHAH 15
STR_SPLIT()
• This funciton splits string into an array.
• <?php
• $n="Nikul Shah";
• print_r(str_split($n));
?>
Array ( [0] => N [1] => i [2] => k [3] => u [4] => l [5] => [6] => S [7] => h [8] => a [9] => h )
NIKUL SHAH 16
STRCMP()
• The strcmp() function compares two strings.
• <?php
• echo strcmp("Nikul","Nik");
• ?>
• 2
NIKUL SHAH 17
STRTOLOWER()
• Converts string from uppercase to lower case.
• <?php
• echo strtolower("Nikul Shah");
• ?>
NIKUL SHAH 18
STRTOUPPER()
• Converts string from lowercase to upper case.
• <?php
• echo strtoupper("Nikul Shah");
• ?>
NIKUL SHAH 19
TRIM()
• This function removes the while space.
• <?php
• $str = "Nikul Shah!";
• echo $str . "<br>";
• echo trim($str,"Nik");
• ?>
• Nikul Shah!
ul Shah!
NIKUL SHAH 20
NUMBER_FORMAT()
• This function formats a number with grouped.
• <?php
• echo number_format("100000",1);
• ?>
• 100,000.0
NIKUL SHAH 21
RTIRM()
• Removes white space or other char. From right hand side of the string.
• <?php
• $str = "Nikul Shah!";
• echo $str . "<br>";
• echo rtrim($str,"l Sah!");
• ?>
• Nikul Shah!
Niku
NIKUL SHAH 22
STR_IREPLACE()
• Replaces some char of the string.
• <?php
• echo str_ireplace("Nikul", "hi","hey hello");
• ?>
• hey hello
NIKUL SHAH 23
STR_REPEAT()
• str_repeat() function repeats a string a specified number of times.
• <?php
• echo str_repeat("Nikul",10);
• ?>
• NikulNikulNikulNikulNikulNikulNikulNikulNikulNikul
NIKUL SHAH 24
STR_REPLACE()
• <?php
• $r=array("hello","hey", "Nikul","hello");
• print_r(str_replace("hello","hi",$r,$i));
• echo"<br>";
• echo "replacements are :$i";
• ?>
• Array ( [0] => hi [1] => hey [2] => Nikul [3] => hi )
replacements are :2
NIKUL SHAH 25
STR_SHUFFLE()
• <?php
• echo str_shuffle("Nikul");
• ?>
• ikuNl
NIKUL SHAH 26
STR_WORD_COUNT()
• Counts the word in the string.
• <?php
• echo str_word_count("Nikul Shah");
• ?>
• 2
NIKUL SHAH 27
STRCASECMP()
<?php
• echo strcasecmp("Nikul","Nikul");
• ?>
• 0 If this function returns 0, the two strings are equal.
• 0 - if the two strings are equal
• <0 - if string1 is less than string2
• >0 - if string1 is greater than string2
NIKUL SHAH 28
STR_PAD()
• <?php
• $str = "Hello Nikul";
• echo str_pad($str,40,".");
• ?>
• Hello Nikul.............................
NIKUL SHAH 29
STRCSPN()
• Retruns the no of char found in a string before any part of some specified char are found.
• <?php
• $str = "Hello Nikul";
• echo strcspn($str,"N");
• ?>
• 6
NIKUL SHAH 30
STRCHR()
• Finds the first occurrence of a string inside another string . Alias strstr().
• This is case sensitive.
• <?php
• $str = "Hello Nikul";
• echo strchr($str,“Nikul");
• ?>
NIKUL SHAH 31
STRISTR()
• Finds the first occurrence of a string inside another string . Alias strstr().
• This is case insensitive.
• $str = "Hello Nikul";
• echo strchr($str,“nikul");
• ?>
NIKUL SHAH 32
STRIPOS()
• stripos() function finds the position of the first occurrence of a string inside another string.
• <?php
• echo stripos("today is Sunday","Sunday");
• ?>
NIKUL SHAH 33
STRSPN()
• Returns the number of characters found in a string that contains only characters from a
specified charlist
• <?php
• echo strspn("Nikul","ikul");
• ?>
• 0
NIKUL SHAH 34
CONVERT_UUENCODE()
• <?php
$str = "Hello Nikul!";
echo convert_uuencode($str);
?>
• convert_uudecode()
• $decodeString = convert_uudecode($encodeString);
echo $decodeString;
NIKUL SHAH 35
ENJOYED !!! ???
NEXT ARRAY.
BY NIKUL SHAH
NIKUL SHAH 36

More Related Content

DOCX
Sql seuence and sub queries
PDF
PHP Static Code Review
PDF
Swift, functional programming, and the future of Objective-C
PDF
Swift 함수 커링 사용하기
PDF
On Functional Programming - A Clojurian Perspective
ODP
EcmaScript 6
PDF
DEF CON 27 -OMER GULL - select code execution from using sq lite
PDF
ClojurianからみたElixir
Sql seuence and sub queries
PHP Static Code Review
Swift, functional programming, and the future of Objective-C
Swift 함수 커링 사용하기
On Functional Programming - A Clojurian Perspective
EcmaScript 6
DEF CON 27 -OMER GULL - select code execution from using sq lite
ClojurianからみたElixir

What's hot (20)

PPTX
Perl6 a whistle stop tour
PDF
Perl6 a whistle stop tour
PDF
... now write an interpreter (PHPem 2016)
PDF
Elm: give it a try
PDF
Pre-Bootcamp introduction to Elixir
PDF
Optimizing Queries with Explain
PPTX
Fact, Fiction, and FP
PPTX
Ricky Bobby's World
ODP
PDF
Cycle.js: Functional and Reactive
PDF
Python postgre sql a wonderful wedding
KEY
Indexing thousands of writes per second with redis
PDF
Java Cheat Sheet
PDF
Refactoring to Macros with Clojure
PDF
ECMAScript 6 new features
KEY
Into Clojure
PDF
56 Query Optimization
PDF
PDF
Efficient Use of indexes in MySQL
PDF
ECMAScript 6 and beyond
Perl6 a whistle stop tour
Perl6 a whistle stop tour
... now write an interpreter (PHPem 2016)
Elm: give it a try
Pre-Bootcamp introduction to Elixir
Optimizing Queries with Explain
Fact, Fiction, and FP
Ricky Bobby's World
Cycle.js: Functional and Reactive
Python postgre sql a wonderful wedding
Indexing thousands of writes per second with redis
Java Cheat Sheet
Refactoring to Macros with Clojure
ECMAScript 6 new features
Into Clojure
56 Query Optimization
Efficient Use of indexes in MySQL
ECMAScript 6 and beyond
Ad

Viewers also liked (7)

PPT
strings
PPTX
Implementation Of String Functions In C
PPTX
String function
PDF
Implementation of c string functions
PPTX
Strings in C
DOC
String in c
PPT
Strings Functions in C Programming
strings
Implementation Of String Functions In C
String function
Implementation of c string functions
Strings in C
String in c
Strings Functions in C Programming
Ad

Similar to String functions (20)

PPTX
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
PPTX
UNIT IV (4).pptx
PDF
Paradigma FP y OOP usando técnicas avanzadas de Programación | Programacion A...
PPTX
String handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering College
PPTX
UNIT II (7).pptx
PPTX
UNIT II (7).pptx
PDF
PyCon2009_AI_Alt
PPTX
Function & Recursion
PPTX
PY_17_06_20-1.pptx
PDF
Beautiful python - PyLadies
PPTX
MYSQL single rowfunc-multirowfunc-groupby-having
PDF
Php array
PPTX
strings in php how to use different data types in string
PPTX
Presentation on php string function part-1
PPT
Javascript built in String Functions
PPTX
week 4 Programming lecture 08asfsfsd.pptx
PPTX
Lecture 1 string functions
PPT
Lecture#9 Arrays in c++
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
UNIT IV (4).pptx
Paradigma FP y OOP usando técnicas avanzadas de Programación | Programacion A...
String handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering College
UNIT II (7).pptx
UNIT II (7).pptx
PyCon2009_AI_Alt
Function & Recursion
PY_17_06_20-1.pptx
Beautiful python - PyLadies
MYSQL single rowfunc-multirowfunc-groupby-having
Php array
strings in php how to use different data types in string
Presentation on php string function part-1
Javascript built in String Functions
week 4 Programming lecture 08asfsfsd.pptx
Lecture 1 string functions
Lecture#9 Arrays in c++

Recently uploaded (20)

PPTX
Pharma ospi slides which help in ospi learning
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Pre independence Education in Inndia.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
RMMM.pdf make it easy to upload and study
PDF
Insiders guide to clinical Medicine.pdf
PPTX
Cell Types and Its function , kingdom of life
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Cell Structure & Organelles in detailed.
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Pharma ospi slides which help in ospi learning
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
O7-L3 Supply Chain Operations - ICLT Program
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Basic Mud Logging Guide for educational purpose
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Complications of Minimal Access Surgery at WLH
Renaissance Architecture: A Journey from Faith to Humanism
VCE English Exam - Section C Student Revision Booklet
Pre independence Education in Inndia.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
RMMM.pdf make it easy to upload and study
Insiders guide to clinical Medicine.pdf
Cell Types and Its function , kingdom of life
Supply Chain Operations Speaking Notes -ICLT Program
Cell Structure & Organelles in detailed.
school management -TNTEU- B.Ed., Semester II Unit 1.pptx

String functions

  • 1. Created by Nikul Shah STRING FUNCTIONS NIKUL SHAH 1
  • 2. STRLEN() • <?php • echo strlen("Hello Nikul!"); • ?> • /*output */ • 12 NIKUL SHAH 2
  • 3. STR_WORD_COUNT() • <?php • echo str_word_count("Some people tend to forget that kindness and manners are free."); • ?> NIKUL SHAH 3
  • 4. STRREV() • <?php • echo strrev("don't loss your hope."); • ?> NIKUL SHAH 4
  • 5. STRPOS() • strpos() function searches for a specific text within a string. • If a match is found, the function returns the character position of the first match. If no match is found, it will return FALSE. • <?php • echo strpos("Destiny works.", "works"); • ?> NIKUL SHAH 5
  • 6. STR_REPLACE ------ STRTR • $search = array('A', 'B', 'C', 'D', 'E'); • $replace = array('B', 'C', 'D', 'E', 'F'); • $subject = 'A'; • $trans = array('A' => 'B','B'=>'C','C'=>'D','D'=>'E','E'=>'F'); • echo str_replace($search, $replace, $subject); • echo "<br/>"; • echo strtr($subject,$trans); NIKUL SHAH 6
  • 7. • <?php • echo str_replace("Nikul","Shah","Nik shah"); • ?> NIKUL SHAH 7
  • 8. ADDSLASHES() • <?php • $str=addslashes("today is 'monday'"); • echo "$str"; • ?> • //output • today is 'monday' NIKUL SHAH 8
  • 9. ADDCSLASHES() • <?php • $str=addcslashes("Nikul","k"); • echo "$str"; • ?> • Be careful using addcslashes() on 0 (NULL), r (carriage return), n (newline), f (form feed), t (tab) and v (vertical tab). In PHP, 0, r, n, t, f and v are predefined escape sequences. NIKUL SHAH 9
  • 10. CHR() • The chr() function returns a character from the specified ASCII value. • The ASCII value can be specified in decimal, octal, or hex values. Octal values are defined by a leading 0, while hex values are defined by a leading 0x. • <?php $str = chr(43); $str2 = chr(61); echo("2 $str 2 $str2 4"); ?> NIKUL SHAH 10
  • 11. EXPLODE() • The explode() function breaks a string into an array. • Note: The "separator" parameter cannot be an empty string. • <?php • $str="Hello my name is 'Nikul'"; • print_r (explode(" ",$str)); • print_r(explode(',',$str,0)); • ?> • Using limits parameter it will returns no of elements. • This function can not run on echo. NIKUL SHAH 11
  • 12. IMPLODE() • implode() function returns a string from the elements of an array • <?php • $str =array('Hello','Nikul','How','are','You?'); • print_r(implode(",",$str)); • ?>. NIKUL SHAH 12
  • 13. JOIN() • Joins array into string. Same as implode() • <?php • $im=array("nikul","Shah"); • echo (join(" ",$im)); • ?> NIKUL SHAH 13
  • 14. MD5() • This function Calculates the MD5 hash of a string. • <?php • $im=array("nikul","Shah"); • echo md5(join(" ",$im)); • ?> • 4994812ba7d125a30e2b9c04e7b7c014 NIKUL SHAH 14
  • 15. NL2BR() • Inserts HTML line breaks in front of each newline in a string • <?php • $n="Nikul nShah"; • echo nl2br($n); • ?> NIKUL SHAH 15
  • 16. STR_SPLIT() • This funciton splits string into an array. • <?php • $n="Nikul Shah"; • print_r(str_split($n)); ?> Array ( [0] => N [1] => i [2] => k [3] => u [4] => l [5] => [6] => S [7] => h [8] => a [9] => h ) NIKUL SHAH 16
  • 17. STRCMP() • The strcmp() function compares two strings. • <?php • echo strcmp("Nikul","Nik"); • ?> • 2 NIKUL SHAH 17
  • 18. STRTOLOWER() • Converts string from uppercase to lower case. • <?php • echo strtolower("Nikul Shah"); • ?> NIKUL SHAH 18
  • 19. STRTOUPPER() • Converts string from lowercase to upper case. • <?php • echo strtoupper("Nikul Shah"); • ?> NIKUL SHAH 19
  • 20. TRIM() • This function removes the while space. • <?php • $str = "Nikul Shah!"; • echo $str . "<br>"; • echo trim($str,"Nik"); • ?> • Nikul Shah! ul Shah! NIKUL SHAH 20
  • 21. NUMBER_FORMAT() • This function formats a number with grouped. • <?php • echo number_format("100000",1); • ?> • 100,000.0 NIKUL SHAH 21
  • 22. RTIRM() • Removes white space or other char. From right hand side of the string. • <?php • $str = "Nikul Shah!"; • echo $str . "<br>"; • echo rtrim($str,"l Sah!"); • ?> • Nikul Shah! Niku NIKUL SHAH 22
  • 23. STR_IREPLACE() • Replaces some char of the string. • <?php • echo str_ireplace("Nikul", "hi","hey hello"); • ?> • hey hello NIKUL SHAH 23
  • 24. STR_REPEAT() • str_repeat() function repeats a string a specified number of times. • <?php • echo str_repeat("Nikul",10); • ?> • NikulNikulNikulNikulNikulNikulNikulNikulNikulNikul NIKUL SHAH 24
  • 25. STR_REPLACE() • <?php • $r=array("hello","hey", "Nikul","hello"); • print_r(str_replace("hello","hi",$r,$i)); • echo"<br>"; • echo "replacements are :$i"; • ?> • Array ( [0] => hi [1] => hey [2] => Nikul [3] => hi ) replacements are :2 NIKUL SHAH 25
  • 26. STR_SHUFFLE() • <?php • echo str_shuffle("Nikul"); • ?> • ikuNl NIKUL SHAH 26
  • 27. STR_WORD_COUNT() • Counts the word in the string. • <?php • echo str_word_count("Nikul Shah"); • ?> • 2 NIKUL SHAH 27
  • 28. STRCASECMP() <?php • echo strcasecmp("Nikul","Nikul"); • ?> • 0 If this function returns 0, the two strings are equal. • 0 - if the two strings are equal • <0 - if string1 is less than string2 • >0 - if string1 is greater than string2 NIKUL SHAH 28
  • 29. STR_PAD() • <?php • $str = "Hello Nikul"; • echo str_pad($str,40,"."); • ?> • Hello Nikul............................. NIKUL SHAH 29
  • 30. STRCSPN() • Retruns the no of char found in a string before any part of some specified char are found. • <?php • $str = "Hello Nikul"; • echo strcspn($str,"N"); • ?> • 6 NIKUL SHAH 30
  • 31. STRCHR() • Finds the first occurrence of a string inside another string . Alias strstr(). • This is case sensitive. • <?php • $str = "Hello Nikul"; • echo strchr($str,“Nikul"); • ?> NIKUL SHAH 31
  • 32. STRISTR() • Finds the first occurrence of a string inside another string . Alias strstr(). • This is case insensitive. • $str = "Hello Nikul"; • echo strchr($str,“nikul"); • ?> NIKUL SHAH 32
  • 33. STRIPOS() • stripos() function finds the position of the first occurrence of a string inside another string. • <?php • echo stripos("today is Sunday","Sunday"); • ?> NIKUL SHAH 33
  • 34. STRSPN() • Returns the number of characters found in a string that contains only characters from a specified charlist • <?php • echo strspn("Nikul","ikul"); • ?> • 0 NIKUL SHAH 34
  • 35. CONVERT_UUENCODE() • <?php $str = "Hello Nikul!"; echo convert_uuencode($str); ?> • convert_uudecode() • $decodeString = convert_uudecode($encodeString); echo $decodeString; NIKUL SHAH 35
  • 36. ENJOYED !!! ??? NEXT ARRAY. BY NIKUL SHAH NIKUL SHAH 36