Výukový program PHP

PHP HOME Úvod do PHP Instalace PHP Syntaxe PHP Komentáře PHP PHP proměnné PHP Echo / tisk Datové typy PHP PHP řetězce PHP čísla PHP matematika Konstanty PHP Operátoři PHP PHP If...Else...Elseif Přepínač PHP PHP smyčky Funkce PHP Pole PHP PHP Superglobals PHP RegEx

Formuláře PHP

Manipulace s formuláři PHP Ověření formuláře PHP Je vyžadován formulář PHP Adresa URL / e-mail PHP formuláře Formulář PHP dokončen

PHP pro pokročilé

Datum a čas PHP Zahrnout PHP Práce se soubory PHP PHP soubor otevřít/číst Vytvoření/zápis souboru PHP Nahrání souboru PHP PHP soubory cookie PHP relace PHP filtry Pokročilé filtry PHP Funkce zpětného volání PHP PHP JSON Výjimky PHP

PHP OOP

PHP Co je OOP PHP třídy/objekty PHP konstruktor PHP destruktor Modifikátory přístupu PHP Dědičnost PHP Konstanty PHP Abstraktní třídy PHP Rozhraní PHP Vlastnosti PHP Statické metody PHP Statické vlastnosti PHP Jmenné prostory PHP PHP Iterables

Databáze MySQL

Databáze MySQL Připojení MySQL MySQL Vytvořte DB Vytvořit tabulku MySQL Vložit data MySQL MySQL Get Last ID MySQL Insert Multiple MySQL připraveno MySQL Select Data Kde MySQL Pořadí MySQL podle Vymazání dat MySQL Aktualizace dat MySQL Limit dat MySQL

PHP XML

PHP analyzátory XML PHP SimpleXML Parser PHP SimpleXML - Získejte PHP XML expat PHP XML DOM

PHP - AJAX

Úvod do AJAXu AJAX PHP Databáze AJAX AJAX XML AJAX Live Search Anketa AJAX

Příklady PHP

Příklady PHP PHP kompilátor PHP kvíz Cvičení PHP Certifikát PHP

Reference PHP

Přehled PHP Pole PHP Kalendář PHP Datum PHP Adresář PHP Chyba PHP Výjimka PHP Souborový systém PHP PHP filtr PHP FTP PHP JSON Klíčová slova PHP PHP Libxml PHP Mail PHP matematika PHP Různé PHP MySQLi Síť PHP Ovládání výstupu PHP PHP RegEx PHP SimpleXML PHP stream PHP řetězec PHP Variable Handling PHP XML Parser PHP zip Časová pásma PHP

PHP funkce regulárních výrazů


Úvod do regulárních výrazů PHP

Regulární výrazy umožňují vyhledávat a nahrazovat vzory v řetězcích.


Instalace

Funkce regulárních výrazů PHP jsou součástí jádra PHP. Pro použití těchto funkcí není nutná žádná instalace.


Konfigurace běhového prostředí

Tato nastavení v php.ini lze použít k omezení množství času nebo zdrojů použitých při vyhodnocování regulárních výrazů.

Name Default Description Changeable
pcre.backtrack_limit "1000000" The maximum number of backtracks that the regular expression engine is allowed to do while evaluating an expression. (available since PHP 5.2) PHP_INI_ALL
pcre.recursion_limit "100000" The maximum recursion depth that the regular expression engine is permitted to reach while evaluating an expression. (available since PHP 5.2) PHP_INI_ALL
pcre.jit "1" When set to "1" this enables PCRE's (Perl-Compatible Regular Expressions) just-in-time compilation. (available since PHP 7.0) PHP_INI_ALL

PHP funkce regulárních výrazů

Function Description
preg_filter() Returns a string or an array with pattern matches replaced, but only if matches were found
preg_grep() Returns an array consisting only of elements from the input array which matched the pattern
preg_last_error() Returns an error code indicating the reason that the most recent regular expression call failed
preg_match() Finds the first match of a pattern in a string
preg_match_all() Finds all matches of a pattern in a string
preg_replace() Returns a string where matches of a pattern (or an array of patterns) are replaced with a substring (or an array of substrings) in a given string
preg_replace_callback() Given an expression and a callback, returns a string where all matches of the expression are replaced with the substring returned by the callback
preg_replace_callback_array() Given an array associating expressions with callbacks, returns a string where all matches of each expression are replaced with the substring returned by the callback
preg_split() Breaks a string into an array using matches of a regular expression as separators
preg_quote() Escapes characters that have a special meaning in regular expressions by putting a backslash in front of them

Modifikátory regulárních výrazů

Modifikátory mohou změnit způsob provádění vyhledávání.

Modifier Description
i Performs a case-insensitive search
m Performs a multiline search (patterns that search for the beginning or end of a string will match the beginning or end of each line)
u Enables correct matching of UTF-8 encoded patterns

Vzory regulárních výrazů

Závorky se používají k nalezení řady znaků:

Expression Description
[abc] Find one character from the options between the brackets
[^abc] Find any character NOT between the brackets
[0-9] Find one character from the range 0 to 9

Metaznaky

Metaznaky jsou znaky se zvláštním významem:

Metacharacter Description
| Find a match for any one of the patterns separated by | as in: cat|dog|fish
. Find just one instance of any character
^ Finds a match as the beginning of a string as in: ^Hello
$ Finds a match at the end of the string as in: World$
\d Find a digit
\s Find a whitespace character
\b Find a match at the beginning of a word like this: \bWORD, or at the end of a word like this: WORD\b
\uxxxx Find the Unicode character specified by the hexadecimal number xxxx

Kvantifikátory

Kvantifikátory definují množství:

Quantifier Description
n+ Matches any string that contains at least one n
n* Matches any string that contains zero or more occurrences of n
n? Matches any string that contains zero or one occurrences of n
n{x} Matches any string that contains a sequence of X n's
n{x,y} Matches any string that contains a sequence of X to Y n's
n{x,} Matches any string that contains a sequence of at least X n's

Poznámka: Pokud váš výraz potřebuje vyhledat jeden ze speciálních znaků, můžete je ukončit pomocí zpětného lomítka ( \ ). Například pro hledání jednoho nebo více otazníků můžete použít následující výraz: $pattern = '/\?+/';