SlideShare a Scribd company logo
1 of 26
Introduction toIntroduction to
STRINGSTRING
HandlingHandling
StringStringlerler
$a = trim($name); //kırpma
$a = nl2br(“line1nline2”); // “line1 br line2”< > çevirir
printf(“total %d”, 15); // prints to stdout
Strings in PHPStrings in PHP
A string is an array of character.
$a = strtoupper($name); // büyük harf
$a = strtolower($name); // küçük harf
$a = ucfirst($name); // İlk karakterbüyük
$text = "A very long woooooooooooord.";
$newtext = wordwrap($text, 8, "n", 1);
$a = crpyt($a); // şifreleme
$a = decrypt(encrpyt($a)); // 2-way encription
with Mcrpt extension
Strings in PHPStrings in PHP
Slash ekler- (veritabanına eklerken)
$a = AddSlashes($typedText);
Slashları kaldırır
$a = StripSlashes($typedText);
StringString birleştirme vebirleştirme ve
ayırmaayırma
?<
$pizza = "piece1 piece2 piece3 piece4 piece5";
$pieces = explode (" ", $pizza); // split string into pieces
for($i=0; $i count($pieces); $i++)<
echo "- $pieces[$i] br ";> < >
echo implode(“:", $pieces); // join strings using “:“
?>
Stringleri ayırmaStringleri ayırma
$string = "This is an example string";
$tok = strtok ($string," ");
while ($tok) {
echo "Word=$tok<br>";
$tok = strtok (" ");
}
Strings in PHPStrings in PHP
• string substr (string string, int start [, int length])
• int strlen (string str)
• int strcmp (string str1, string str2) Returns
o < 0 if str1 is less than str2;
o > 0 if str1 is greater than str2,
o 0 if they are equal.
Regular ExpressionsRegular Expressions
• A way of describing a pattern in string
• Use special characters to indicate meta-meaning in
addition to exact matching.
• More powerful than exact matching
• There are 2 sets of function on regular expressions in
PHP
o Functions using POSIX-type reg expr
o Functions using Perl-type reg expr
Regular ExpressionsRegular Expressions
“.” tek bir karakterle eşleşir
.at == “cat”, “sat”, etc.
[a-zA-Z0-9] tek bir karakterle (a-zA-Z0-9)
arasında eşleşir.
[^0-9] rakam olmayan birşeyle eşleşir.
Regular Expr: Built-inRegular Expr: Built-in
Char-setsChar-sets
• [[:alphanum:]] --harf
• [[:digit:]] rakamla
• [[:space:]] boşlukla
Regular ExprRegular Expr
• . Tek karakter
• + 1 ya da daha fazla bulunan stringle
• * 0 ya da daha fazla bulunan stringle
• [a-z] karakter
• ^ değil anlamında
• $ string sonu
• | or
•  özel karakterleri atlar
• (sub-expr) -- sub-expression
• (sub-expr){i,j} i min i, max j ile sub-expr olma durumu
Reg Expr Functions (Perl)Reg Expr Functions (Perl)
• preg_match — Perform a reg expr match
• preg_match_all — Perform a global r.e. match
• preg_replace — Perform a re search & replace
• preg_split — Split string by a reg expr
preg_match -- Perform apreg_match -- Perform a
re matchre match
int preg_match (string pattern, string subject [, array
matches])
• Searches subject for a match to the reg expr given
in pattern.
• Return one match for each subpattern () only
• $matches[0]: the text matching the full pattern
• $matches[1]: the text that matched the first
captured parenthesized subpattern, and so on.
• Returns true if a match for pattern was found
preg_match -- Perform apreg_match -- Perform a
re matchre match
preg_match("/pattern/modifier", subject, array)
Modifiers:
• i: case insensitive search
• m: by default subject is treated single-line even if it contains
newlines, m makes PCRE treat subject multiline (for ^, $)
• s: makes . metacharacter match n
• x: whitespace in pattern is ignored
• E: $ matches only at the end of subject
• U: behave ungreedy (comert)
preg_match -- Perform apreg_match -- Perform a
re matchre match$s = <<<STR
<table><tr><td>cell1</td><td>cell2</td></tr>
<tr><td>cell3</td><td>cell4</td></tr></table>
STR;
preg_match("/<table>(.*)</table>/Us", $s, $r)
// anything between <table> and </table>
preg_match("/<tr><td>(.*)</td><td>(.*)</td></tr>/Us", $r[1],
$t)
// matches cell1 and cell2
preg_match("/<tr>(.*)</tr>/Us", $r[1], $t);
// matches <td>cell1</td><td>cell2</td>
preg_matchpreg_match_all:_all: Perform Perform globalglobal matchmatch
int preg_match_all (string pattern, string subject, array
matches [, int order])
• Searches subject for all matches and puts them in
matches in the order specified by order.
• After the first match, the subsequent ones are
continued on from end of the last match.
• $matches[0] is an array of full pattern matches
• $matches[1] is an array of strings matched by the
first parenthesized subpattern, and so on.
preg_matchpreg_match_all:_all: Perform Perform globalglobal matchmatch
preg_match("/<table>(.*)</table>/Us", $s, $r);
preg_match_all("/<tr><td>(.*)</td><td>(.*)</td></
tr>/Us", $r[1], $t);
echo $t[1][0],$t[1][1],$t[2][0],$t[2][1];
// prints cell1cell3cell2cell4
preg_match_all("/<tr><td>(.*)</td><td>(.*)</td></
tr>/Us", $r[1], $t, PREG_SET_ORDER );
//Orders results so that $matches[0] is an array of first
set of matches, $matches[1] is an array of second
set of matches,…
echo $t[0][1],$t[0][2],$t[1][1],$t[1][2];
// returns cell1cell2cell3cell4
preg_matchpreg_match_all:_all: Perform Perform globalglobal matchmatch
Back reference
preg_match_all ("/(<([w]+)[^>]*>)(.*)(</2>)/",
$html, $matches);
// 2 means [w]+
preg_match_all ("|<[^>]+>(.*)</[^>]+>|U", $html, $m)
// return text in html tags
Convert HTML to TextConvert HTML to Text
$html = file(“http://www.page.com”);
$search = array ("'<script[^>]*?>.*?</script>'si",
"'<[/!]*?[^<>]*?>'si",
"'([rn])[s]+'",
"'&(quote|#34);'i",
"'&(amp|#38);'i", …);
$replace = array ("", "", "1", """, "&", …);
$text = preg_replace ($search, $replace, $html);
Reg Expr FunctionsReg Expr Functions
(POSIX)(POSIX)
• ereg (string pattern, string string [, array regs])
o Searches a string for matches to the regular expression given in pattern.
• ereg_replace (string pattern, string subs, string string)
o Scans string for matches to pattern, then replaces the matched text with
subs.
• array split (string pattern, string string [, int limit])
o Split string using pattern
Regular ExprRegular Expr
ereg ("abc", $string);
ereg ("^abc", $string);
ereg ("abc$", $string);
eregi ("(ozilla.[23]|MSIE.3)", $HTTP_USER_AGENT);
ereg ("([[:alnum:]]+) ([[:alnum:]]+) ([[:alnum:]]+)",
$string,$regs);
$string = ereg_replace ("^", "<BR>", $string);
$string = ereg_replace ("$", "<BR>", $string);
$string = ereg_replace ("n", "", $string);
Regular ExprRegular Expr
if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date,
$regs)) {
echo "$regs[3].$regs[2].$regs[1]";
}else{
echo "Invalid date format: $date";
}
Regular ExprRegular Expr
$string = "This is a test";
echo ereg_replace (" is", " was", $string);
echo ereg_replace ("( )is", "1was", $string);
echo ereg_replace ("(( )is)", "2was", $string);
Regular ExprRegular Expr
$date = "04/30/1973";
// Delimiters may be slash, dot, or hyphen list
($month, $day, $year) = split ('[/.-]', $date);
echo "Month: $month; Day: $day; Year: $year";
ThankThank You !!!You !!!
For More Information click below link:
Follow Us on:
http://vibranttechnologies.co.in/php-classes-in-
mumbai.html

More Related Content

What's hot (20)

Hashes
HashesHashes
Hashes
 
Perl 6 for Concurrency and Parallel Computing
Perl 6 for Concurrency and Parallel ComputingPerl 6 for Concurrency and Parallel Computing
Perl 6 for Concurrency and Parallel Computing
 
Switching from java to groovy
Switching from java to groovySwitching from java to groovy
Switching from java to groovy
 
Python Workshop
Python  Workshop Python  Workshop
Python Workshop
 
Php String And Regular Expressions
Php String  And Regular ExpressionsPhp String  And Regular Expressions
Php String And Regular Expressions
 
Perl 6 by example
Perl 6 by examplePerl 6 by example
Perl 6 by example
 
Ruby cheat sheet
Ruby cheat sheetRuby cheat sheet
Ruby cheat sheet
 
Php Basics Iterations, looping
Php Basics Iterations, loopingPhp Basics Iterations, looping
Php Basics Iterations, looping
 
Achieving Parsing Sanity In Erlang
Achieving Parsing Sanity In ErlangAchieving Parsing Sanity In Erlang
Achieving Parsing Sanity In Erlang
 
Learn python - for beginners - part-2
Learn python - for beginners - part-2Learn python - for beginners - part-2
Learn python - for beginners - part-2
 
Five
FiveFive
Five
 
Perl6 one-liners
Perl6 one-linersPerl6 one-liners
Perl6 one-liners
 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
 
php string part 3
php string part 3php string part 3
php string part 3
 
WordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPressWordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPress
 
Practical approach to perl day2
Practical approach to perl day2Practical approach to perl day2
Practical approach to perl day2
 
Lists and arrays
Lists and arraysLists and arrays
Lists and arrays
 
Bioinformatics p2-p3-perl-regexes v2014
Bioinformatics p2-p3-perl-regexes v2014Bioinformatics p2-p3-perl-regexes v2014
Bioinformatics p2-p3-perl-regexes v2014
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6
 
Gigigo Ruby Workshop
Gigigo Ruby WorkshopGigigo Ruby Workshop
Gigigo Ruby Workshop
 

Viewers also liked (15)

Php Using Arrays
Php Using ArraysPhp Using Arrays
Php Using Arrays
 
Control Structures In Php 2
Control Structures In Php 2Control Structures In Php 2
Control Structures In Php 2
 
Chapter 02 php basic syntax
Chapter 02   php basic syntaxChapter 02   php basic syntax
Chapter 02 php basic syntax
 
PHP
PHPPHP
PHP
 
PHP
PHPPHP
PHP
 
PHP variables
PHP  variablesPHP  variables
PHP variables
 
Php string function
Php string function Php string function
Php string function
 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
 
Php string
Php stringPhp string
Php string
 
Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
 
Cookie and session
Cookie and sessionCookie and session
Cookie and session
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
 
PHP slides
PHP slidesPHP slides
PHP slides
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 

Similar to PHP - Introduction to String Handling

Bioinformatica 06-10-2011-p2 introduction
Bioinformatica 06-10-2011-p2 introductionBioinformatica 06-10-2011-p2 introduction
Bioinformatica 06-10-2011-p2 introductionProf. Wim Van Criekinge
 
Talk Unix Shell Script
Talk Unix Shell ScriptTalk Unix Shell Script
Talk Unix Shell ScriptDr.Ravi
 
Regular expressionfunction
Regular expressionfunctionRegular expressionfunction
Regular expressionfunctionADARSH BHATT
 
Talk Unix Shell Script 1
Talk Unix Shell Script 1Talk Unix Shell Script 1
Talk Unix Shell Script 1Dr.Ravi
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsRaj Gupta
 
Regular Expressions in PHP, MySQL by programmerblog.net
Regular Expressions in PHP, MySQL by programmerblog.netRegular Expressions in PHP, MySQL by programmerblog.net
Regular Expressions in PHP, MySQL by programmerblog.netProgrammer Blog
 
Eag 201110-hrugregexpresentation-111006104128-phpapp02
Eag 201110-hrugregexpresentation-111006104128-phpapp02Eag 201110-hrugregexpresentation-111006104128-phpapp02
Eag 201110-hrugregexpresentation-111006104128-phpapp02egoodwintx
 
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Andrea Telatin
 
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekinge
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekingeBioinformatics p2-p3-perl-regexes v2013-wim_vancriekinge
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekingeProf. Wim Van Criekinge
 
Perl.predefined.variables
Perl.predefined.variablesPerl.predefined.variables
Perl.predefined.variablesKing Hom
 
Php Chapter 4 Training
Php Chapter 4 TrainingPhp Chapter 4 Training
Php Chapter 4 TrainingChris Chubb
 
Unit 1-array,lists and hashes
Unit 1-array,lists and hashesUnit 1-array,lists and hashes
Unit 1-array,lists and hashessana mateen
 
Basic regular expression, extended regular expression
Basic regular expression, extended regular expressionBasic regular expression, extended regular expression
Basic regular expression, extended regular expressionDr. Girish GS
 
Climbing the Abstract Syntax Tree (IPC Fall 2017)
Climbing the Abstract Syntax Tree (IPC Fall 2017)Climbing the Abstract Syntax Tree (IPC Fall 2017)
Climbing the Abstract Syntax Tree (IPC Fall 2017)James Titcumb
 
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)James Titcumb
 
3.2 javascript regex
3.2 javascript regex3.2 javascript regex
3.2 javascript regexJalpesh Vasa
 

Similar to PHP - Introduction to String Handling (20)

Bioinformatica 06-10-2011-p2 introduction
Bioinformatica 06-10-2011-p2 introductionBioinformatica 06-10-2011-p2 introduction
Bioinformatica 06-10-2011-p2 introduction
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
 
Talk Unix Shell Script
Talk Unix Shell ScriptTalk Unix Shell Script
Talk Unix Shell Script
 
Regular expressionfunction
Regular expressionfunctionRegular expressionfunction
Regular expressionfunction
 
Talk Unix Shell Script 1
Talk Unix Shell Script 1Talk Unix Shell Script 1
Talk Unix Shell Script 1
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Regular Expressions in PHP, MySQL by programmerblog.net
Regular Expressions in PHP, MySQL by programmerblog.netRegular Expressions in PHP, MySQL by programmerblog.net
Regular Expressions in PHP, MySQL by programmerblog.net
 
Eag 201110-hrugregexpresentation-111006104128-phpapp02
Eag 201110-hrugregexpresentation-111006104128-phpapp02Eag 201110-hrugregexpresentation-111006104128-phpapp02
Eag 201110-hrugregexpresentation-111006104128-phpapp02
 
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
 
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekinge
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekingeBioinformatics p2-p3-perl-regexes v2013-wim_vancriekinge
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekinge
 
Perl.predefined.variables
Perl.predefined.variablesPerl.predefined.variables
Perl.predefined.variables
 
php string part 4
php string part 4php string part 4
php string part 4
 
Php Chapter 4 Training
Php Chapter 4 TrainingPhp Chapter 4 Training
Php Chapter 4 Training
 
Unit 1-array,lists and hashes
Unit 1-array,lists and hashesUnit 1-array,lists and hashes
Unit 1-array,lists and hashes
 
Basic regular expression, extended regular expression
Basic regular expression, extended regular expressionBasic regular expression, extended regular expression
Basic regular expression, extended regular expression
 
Php functions
Php functionsPhp functions
Php functions
 
php_string.pdf
php_string.pdfphp_string.pdf
php_string.pdf
 
Climbing the Abstract Syntax Tree (IPC Fall 2017)
Climbing the Abstract Syntax Tree (IPC Fall 2017)Climbing the Abstract Syntax Tree (IPC Fall 2017)
Climbing the Abstract Syntax Tree (IPC Fall 2017)
 
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)
 
3.2 javascript regex
3.2 javascript regex3.2 javascript regex
3.2 javascript regex
 

More from Vibrant Technologies & Computers

Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.Vibrant Technologies & Computers
 

More from Vibrant Technologies & Computers (20)

Buisness analyst business analysis overview ppt 5
Buisness analyst business analysis overview ppt 5Buisness analyst business analysis overview ppt 5
Buisness analyst business analysis overview ppt 5
 
SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables  SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables
 
SQL- Introduction to MySQL
SQL- Introduction to MySQLSQL- Introduction to MySQL
SQL- Introduction to MySQL
 
SQL- Introduction to SQL database
SQL- Introduction to SQL database SQL- Introduction to SQL database
SQL- Introduction to SQL database
 
ITIL - introduction to ITIL
ITIL - introduction to ITILITIL - introduction to ITIL
ITIL - introduction to ITIL
 
Salesforce - Introduction to Security & Access
Salesforce -  Introduction to Security & Access Salesforce -  Introduction to Security & Access
Salesforce - Introduction to Security & Access
 
Data ware housing- Introduction to olap .
Data ware housing- Introduction to  olap .Data ware housing- Introduction to  olap .
Data ware housing- Introduction to olap .
 
Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.
 
Data ware housing- Introduction to data ware housing
Data ware housing- Introduction to data ware housingData ware housing- Introduction to data ware housing
Data ware housing- Introduction to data ware housing
 
Salesforce - classification of cloud computing
Salesforce - classification of cloud computingSalesforce - classification of cloud computing
Salesforce - classification of cloud computing
 
Salesforce - cloud computing fundamental
Salesforce - cloud computing fundamentalSalesforce - cloud computing fundamental
Salesforce - cloud computing fundamental
 
SQL- Introduction to PL/SQL
SQL- Introduction to  PL/SQLSQL- Introduction to  PL/SQL
SQL- Introduction to PL/SQL
 
SQL- Introduction to advanced sql concepts
SQL- Introduction to  advanced sql conceptsSQL- Introduction to  advanced sql concepts
SQL- Introduction to advanced sql concepts
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
 
SQL- Introduction to SQL Set Operations
SQL- Introduction to SQL Set OperationsSQL- Introduction to SQL Set Operations
SQL- Introduction to SQL Set Operations
 
Sas - Introduction to designing the data mart
Sas - Introduction to designing the data martSas - Introduction to designing the data mart
Sas - Introduction to designing the data mart
 
Sas - Introduction to working under change management
Sas - Introduction to working under change managementSas - Introduction to working under change management
Sas - Introduction to working under change management
 
SAS - overview of SAS
SAS - overview of SASSAS - overview of SAS
SAS - overview of SAS
 
Teradata - Architecture of Teradata
Teradata - Architecture of TeradataTeradata - Architecture of Teradata
Teradata - Architecture of Teradata
 
Teradata - Restoring Data
Teradata - Restoring Data Teradata - Restoring Data
Teradata - Restoring Data
 

Recently uploaded

Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 

Recently uploaded (20)

Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

PHP - Introduction to String Handling

  • 1.
  • 3. StringStringlerler $a = trim($name); //kırpma $a = nl2br(“line1nline2”); // “line1 br line2”< > çevirir printf(“total %d”, 15); // prints to stdout
  • 4. Strings in PHPStrings in PHP A string is an array of character. $a = strtoupper($name); // büyük harf $a = strtolower($name); // küçük harf $a = ucfirst($name); // İlk karakterbüyük $text = "A very long woooooooooooord."; $newtext = wordwrap($text, 8, "n", 1); $a = crpyt($a); // şifreleme $a = decrypt(encrpyt($a)); // 2-way encription with Mcrpt extension
  • 5. Strings in PHPStrings in PHP Slash ekler- (veritabanına eklerken) $a = AddSlashes($typedText); Slashları kaldırır $a = StripSlashes($typedText);
  • 6. StringString birleştirme vebirleştirme ve ayırmaayırma ?< $pizza = "piece1 piece2 piece3 piece4 piece5"; $pieces = explode (" ", $pizza); // split string into pieces for($i=0; $i count($pieces); $i++)< echo "- $pieces[$i] br ";> < > echo implode(“:", $pieces); // join strings using “:“ ?>
  • 7. Stringleri ayırmaStringleri ayırma $string = "This is an example string"; $tok = strtok ($string," "); while ($tok) { echo "Word=$tok<br>"; $tok = strtok (" "); }
  • 8. Strings in PHPStrings in PHP • string substr (string string, int start [, int length]) • int strlen (string str) • int strcmp (string str1, string str2) Returns o < 0 if str1 is less than str2; o > 0 if str1 is greater than str2, o 0 if they are equal.
  • 9. Regular ExpressionsRegular Expressions • A way of describing a pattern in string • Use special characters to indicate meta-meaning in addition to exact matching. • More powerful than exact matching • There are 2 sets of function on regular expressions in PHP o Functions using POSIX-type reg expr o Functions using Perl-type reg expr
  • 10. Regular ExpressionsRegular Expressions “.” tek bir karakterle eşleşir .at == “cat”, “sat”, etc. [a-zA-Z0-9] tek bir karakterle (a-zA-Z0-9) arasında eşleşir. [^0-9] rakam olmayan birşeyle eşleşir.
  • 11. Regular Expr: Built-inRegular Expr: Built-in Char-setsChar-sets • [[:alphanum:]] --harf • [[:digit:]] rakamla • [[:space:]] boşlukla
  • 12. Regular ExprRegular Expr • . Tek karakter • + 1 ya da daha fazla bulunan stringle • * 0 ya da daha fazla bulunan stringle • [a-z] karakter • ^ değil anlamında • $ string sonu • | or • özel karakterleri atlar • (sub-expr) -- sub-expression • (sub-expr){i,j} i min i, max j ile sub-expr olma durumu
  • 13. Reg Expr Functions (Perl)Reg Expr Functions (Perl) • preg_match — Perform a reg expr match • preg_match_all — Perform a global r.e. match • preg_replace — Perform a re search & replace • preg_split — Split string by a reg expr
  • 14. preg_match -- Perform apreg_match -- Perform a re matchre match int preg_match (string pattern, string subject [, array matches]) • Searches subject for a match to the reg expr given in pattern. • Return one match for each subpattern () only • $matches[0]: the text matching the full pattern • $matches[1]: the text that matched the first captured parenthesized subpattern, and so on. • Returns true if a match for pattern was found
  • 15. preg_match -- Perform apreg_match -- Perform a re matchre match preg_match("/pattern/modifier", subject, array) Modifiers: • i: case insensitive search • m: by default subject is treated single-line even if it contains newlines, m makes PCRE treat subject multiline (for ^, $) • s: makes . metacharacter match n • x: whitespace in pattern is ignored • E: $ matches only at the end of subject • U: behave ungreedy (comert)
  • 16. preg_match -- Perform apreg_match -- Perform a re matchre match$s = <<<STR <table><tr><td>cell1</td><td>cell2</td></tr> <tr><td>cell3</td><td>cell4</td></tr></table> STR; preg_match("/<table>(.*)</table>/Us", $s, $r) // anything between <table> and </table> preg_match("/<tr><td>(.*)</td><td>(.*)</td></tr>/Us", $r[1], $t) // matches cell1 and cell2 preg_match("/<tr>(.*)</tr>/Us", $r[1], $t); // matches <td>cell1</td><td>cell2</td>
  • 17. preg_matchpreg_match_all:_all: Perform Perform globalglobal matchmatch int preg_match_all (string pattern, string subject, array matches [, int order]) • Searches subject for all matches and puts them in matches in the order specified by order. • After the first match, the subsequent ones are continued on from end of the last match. • $matches[0] is an array of full pattern matches • $matches[1] is an array of strings matched by the first parenthesized subpattern, and so on.
  • 18. preg_matchpreg_match_all:_all: Perform Perform globalglobal matchmatch preg_match("/<table>(.*)</table>/Us", $s, $r); preg_match_all("/<tr><td>(.*)</td><td>(.*)</td></ tr>/Us", $r[1], $t); echo $t[1][0],$t[1][1],$t[2][0],$t[2][1]; // prints cell1cell3cell2cell4 preg_match_all("/<tr><td>(.*)</td><td>(.*)</td></ tr>/Us", $r[1], $t, PREG_SET_ORDER ); //Orders results so that $matches[0] is an array of first set of matches, $matches[1] is an array of second set of matches,… echo $t[0][1],$t[0][2],$t[1][1],$t[1][2]; // returns cell1cell2cell3cell4
  • 19. preg_matchpreg_match_all:_all: Perform Perform globalglobal matchmatch Back reference preg_match_all ("/(<([w]+)[^>]*>)(.*)(</2>)/", $html, $matches); // 2 means [w]+ preg_match_all ("|<[^>]+>(.*)</[^>]+>|U", $html, $m) // return text in html tags
  • 20. Convert HTML to TextConvert HTML to Text $html = file(“http://www.page.com”); $search = array ("'<script[^>]*?>.*?</script>'si", "'<[/!]*?[^<>]*?>'si", "'([rn])[s]+'", "'&(quote|#34);'i", "'&(amp|#38);'i", …); $replace = array ("", "", "1", """, "&", …); $text = preg_replace ($search, $replace, $html);
  • 21. Reg Expr FunctionsReg Expr Functions (POSIX)(POSIX) • ereg (string pattern, string string [, array regs]) o Searches a string for matches to the regular expression given in pattern. • ereg_replace (string pattern, string subs, string string) o Scans string for matches to pattern, then replaces the matched text with subs. • array split (string pattern, string string [, int limit]) o Split string using pattern
  • 22. Regular ExprRegular Expr ereg ("abc", $string); ereg ("^abc", $string); ereg ("abc$", $string); eregi ("(ozilla.[23]|MSIE.3)", $HTTP_USER_AGENT); ereg ("([[:alnum:]]+) ([[:alnum:]]+) ([[:alnum:]]+)", $string,$regs); $string = ereg_replace ("^", "<BR>", $string); $string = ereg_replace ("$", "<BR>", $string); $string = ereg_replace ("n", "", $string);
  • 23. Regular ExprRegular Expr if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) { echo "$regs[3].$regs[2].$regs[1]"; }else{ echo "Invalid date format: $date"; }
  • 24. Regular ExprRegular Expr $string = "This is a test"; echo ereg_replace (" is", " was", $string); echo ereg_replace ("( )is", "1was", $string); echo ereg_replace ("(( )is)", "2was", $string);
  • 25. Regular ExprRegular Expr $date = "04/30/1973"; // Delimiters may be slash, dot, or hyphen list ($month, $day, $year) = split ('[/.-]', $date); echo "Month: $month; Day: $day; Year: $year";
  • 26. ThankThank You !!!You !!! For More Information click below link: Follow Us on: http://vibranttechnologies.co.in/php-classes-in- mumbai.html