STRINGler. Stringler $a = trim($name);//kırpma $a = nl2br(“line1\nline2”); // “line1 line2” çevirir printf(“total %d”, 15);// prints to stdout.

Slides:



Advertisements
Similar presentations
$100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300.
Advertisements

Презентація за розділом “Гумористичні твори”
Центр атестації педагогічних працівників 2014
Галактики і квазари.
Характеристика ІНДІЇ.
Процюк Н.В. вчитель початкових класів Боярської ЗОШ І – ІІІ ст №4
IS 1181 IS 118 Introduction to Development Tools Chapter 4 String Manipulation and Regular Expressions.
MS3304: Week 4 PHP & HTML Forms. Overview HTML Forms elements refresher Sending data to a script via an HTML form –The post vs. get methods –Name value.
School of Computing and Information Systems CS 371 Web Application Programming PHP - Basics Serving up web pages.
PHP Controlling Program Flow Mohammed M. Hassoun 2012.
PHP: A RRAYS, S TRINGS, AND F ILES CSCI 297 Scripting Languages - Day Three.
If statements and validation. If statement In programming the if statement allows one to test certain conditions and respond differently depending on.
Духовні символи Голосіївського району
Since you’ll need a place for the user to enter a search query. Every form must have these basic components: – The submission type defined with the method.
Scott Marino MSMIS Summer Session Web Site Design and Authoring Session 13 Scott Marino.
Print the sample banner slides or customize with your own message. Click on the letter and type your own text. Use one character per slide. Cut along dotted.
Print the sample banner slides or customize with your own message. Click on the letter and type your own text. Use one character per slide. C.
Test1 Here some text. Text 2 More text.
Click here for the answer. Click here for the answer.
Click here for the answer. Click here for the answer.
Click here for the answer. Click here for the answer.
Log on to and click on the “log in” button
Web Systems Development (CSC-215)
[type text here] [type text here] [type text here] [type text here]
Your text here Your text here Your text here Your text here Your text here Pooky.Pandas.
Put the names of the people in the group here
Your text here Your text here Your text here Your text here
Проф. д-р Васил Цанов, Институт за икономически изследвания при БАН
ЗУТ ПРОЕКТ на Закон за изменение и допълнение на ЗУТ
О Б Щ И Н А С И Л И С Т Р А П р о е к т Б ю д ж е т г.
Електронни услуги на НАП
Боряна Георгиева – директор на
РАЙОНЕН СЪД - БУРГАС РАБОТНА СРЕЩА СЪС СЪДЕБНИТЕ ЗАСЕДАТЕЛИ ПРИ РАЙОНЕН СЪД – БУРГАС 21 ОКТОМВРИ 2016 г.
Сътрудничество между полицията и другите специалисти в България
Съобщение Ръководството на НУ “Христо Ботев“ – гр. Елин Пелин
НАЦИОНАЛНА АГЕНЦИЯ ЗА ПРИХОДИТЕ
ДОБРОВОЛЕН РЕЗЕРВ НА ВЪОРЪЖЕНИТЕ СИЛИ НА РЕПУБЛИКА БЪЛГАРИЯ
Съвременни софтуерни решения
ПО ПЧЕЛАРСТВО ЗА ТРИГОДИШНИЯ
от проучване на общественото мнение,
Васил Големански Ноември, 2006
Програма за развитие на селските райони
ОПЕРАТИВНА ПРОГРАМА “АДМИНИСТРАТИВЕН КАПАЦИТЕТ”
БАЛИСТИКА НА ТЯЛО ПРИ СВОБОДНО ПАДАНЕ В ЗЕМНАТА АТМОСФЕРА
МЕДИЦИНСКИ УНИВЕРСИТЕТ – ПЛЕВЕН
Стратегия за развитие на клъстера 2015
Моето наследствено призвание
Правна кантора “Джингов, Гугински, Кючуков & Величков”
Безопасност на движението
Click here to add your title
String functions
Faculty of Humanities Insert title here.
[type text here] [type text here] [type text here] [type text here]
Put the names of the people in the group here
C Customize this banner with your own message! Select the letter and add your own text. Use one character per slide.
STEP ONE. STEP ONE. STEP ONE. STEP ONE. STEP ONE. 02
회사 소개.
YOUR text YOUR text YOUR text YOUR text
Faculty of Humanities Insert title here.
Refresh: Click Here.
CLICK TO START.
Faculty of Humanities Insert title here.
CLICK TO START.
String functions
Faculty of Humanities Insert title here.
Call Now : Click : -
Call Now : Click : -
Call Now : Click : -
Click here to add your title
Presentation transcript:

STRINGler

Stringler $a = trim($name);//kırpma $a = nl2br(“line1\nline2”); // “line1 line2” çevirir printf(“total %d”, 15);// prints to stdout

URL olarak string gönderme $name = urlencode ($name); $ = urlencode ($_POST[' ']); print "Click here to continue.";

Strings 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 PHP Slash ekler- (veritabanına eklerken) $a = AddSlashes($typedText); Slashları kaldırır $a = StripSlashes($typedText);

String birleştirme ve ayırma <? $pizza = "piece1 piece2 piece3 piece4 piece5"; $pieces = explode (" ", $pizza); // split string into pieces for($i=0; $i<count($pieces); $i++) echo "-> $pieces[$i] "; echo implode(“:", $pieces);// join strings using “:“ ?>

Stringleri ayırma $string = "This is an example string"; $tok = strtok ($string," "); while ($tok) { echo "Word=$tok "; $tok = strtok (" "); }

Strings in PHP string substr (string string, int start [, int length]) int strlen (string str) int strcmp (string str1, string str2) Returns – < 0 if str1 is less than str2; – > 0 if str1 is greater than str2, – 0 if they are equal.

Regular 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 – Functions using POSIX-type reg expr – Functions using Perl-type reg expr

Regular 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-in Char-sets [[:alphanum:]]--harf [[:digit:]]rakamla [[:space:]] boşlukla

Regular 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) preg_match — Perform a reg expr match preg_match preg_match_all — Perform a global r.e. match preg_match_all preg_replace — Perform a re search & replace preg_replace preg_split — Split string by a reg expr preg_split

preg_match -- Perform a re 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 a re 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 a re match $s = <<<STR cell1 cell2 cell3 cell4 STR; preg_match("/ (.*) /Us", $s, $r) // anything between and preg_match("/ (.*) (.*) /Us", $r[1], $t) // matches cell1 and cell2 preg_match("/ (.*) /Us", $r[1], $t); // matches cell1 cell2

preg_match_all: Perform global match 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_match_all: Perform global match preg_match("/ (.*) /Us", $s, $r); preg_match_all("/ (.*) (.*) /Us", $r[1], $t); echo $t[1][0],$t[1][1],$t[2][0],$t[2][1]; // prints cell1cell3cell2cell4 preg_match_all("/ (.*) (.*) /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_match_all: Perform global match Back reference preg_match_all ("/( ]*>)(.*)( )/", $html, $matches); // \\2 means [\w]+\\2 preg_match_all ("| ]+>(.*) ]+>|U", $html, $m)// return text in html tags

Convert HTML to Text $html = file(“ $search = array ("' ]*?>.*? 'si", "' ]*?>'si", "'([\r\n])[\s]+'", "'&(quote|#34);'i", "'&(amp|#38);'i", …); $replace = array ("", "", "\\1", "\"", "&", …); $text = preg_replace ($search, $replace, $html);

Reg Expr Functions (POSIX) ereg (string pattern, string string [, array regs]) – Searches a string for matches to the regular expression given in pattern. ereg_replace (string pattern, string subs, string string) – Scans string for matches to pattern, then replaces the matched text with subs. array split (string pattern, string string [, int limit]) – Split string using pattern

Regular 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 ("^", " ", $string); $string = ereg_replace ("$", " ", $string); $string = ereg_replace ("\n", "", $string);

Regular 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 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 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";