SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 

Kürzlich hochgeladen (20)

Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 

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