บทช่วยสอนPHP

PHP HOME แนะนำ PHP การติดตั้ง PHP PHP ไวยากรณ์ ความคิดเห็น PHP ตัวแปร PHP PHP Echo / พิมพ์ ประเภทข้อมูล PHP PHP Strings หมายเลข PHP PHP คณิตศาสตร์ ค่าคงที่ PHP ตัวดำเนินการ PHP PHP If...Else...Elseif PHP Switch PHP Loops ฟังก์ชัน PHP PHP Arrays PHP Superglobals PHP RegEx

แบบฟอร์มPHP

การจัดการแบบฟอร์ม PHP การตรวจสอบแบบฟอร์ม PHP ต้องใช้แบบฟอร์ม PHP URL แบบฟอร์ม PHP/อีเมล แบบฟอร์ม PHP เสร็จสมบูรณ์

PHPขั้นสูง

วันที่และเวลา PHP รวม PHP การจัดการไฟล์ PHP ไฟล์ PHP เปิด/อ่าน สร้าง/เขียนไฟล์ PHP อัพโหลดไฟล์ PHP คุกกี้ PHP PHP Sessions ตัวกรอง PHP ตัวกรอง PHP ขั้นสูง ฟังก์ชันเรียกกลับของ PHP PHP JSON ข้อยกเว้น PHP

PHP OOP

PHP OOP คืออะไร คลาส PHP/วัตถุ ตัวสร้าง PHP PHP Destructor PHP Access Modifiers PHP Inheritance ค่าคงที่ PHP PHP Abstract Classes อินเทอร์เฟซ PHP PHP ลักษณะ PHP Static Methods PHP คุณสมบัติคงที่ PHP เนมสเปซ PHP Iterables

ฐานข้อมูลMySQL

ฐานข้อมูล MySQL MySQL Connect MySQL สร้าง DB MySQL สร้างตาราง MySQL แทรกข้อมูล MySQL รับ ID ล่าสุด MySQL แทรกหลายรายการ MySQL ที่เตรียมไว้ MySQL Select Data MySQL Where MySQL สั่งซื้อโดย MySQL ลบข้อมูล ข้อมูลอัพเดต MySQL MySQL Limit Data

PHP XML

PHP XML Parsers PHP SimpleXML Parser PHP SimpleXML - รับ PHP XML Expat PHP XML DOM

PHP - AJAX

บทนำ AJAX AJAX PHP ฐานข้อมูล AJAX AJAX XML AJAX ค้นหาสด AJAX โพล

ตัวอย่างPHP

ตัวอย่าง PHP PHP คอมไพเลอร์ แบบทดสอบ PHP แบบฝึกหัด PHP ใบรับรอง PHP

ข้อมูลอ้างอิงPHP

ภาพรวม PHP PHP Array ปฏิทิน PHP PHP วันที่ ไดเรกทอรี PHP ข้อผิดพลาด PHP ข้อยกเว้น PHP ระบบไฟล์ PHP ตัวกรอง PHP PHP FTP PHP JSON คีย์เวิร์ด PHP PHP Libxml PHP Mail PHP คณิตศาสตร์ PHP เบ็ดเตล็ด PHP MySQLi เครือข่าย PHP การควบคุมเอาต์พุต PHP PHP RegEx PHP SimpleXML PHP Stream PHP String การจัดการตัวแปร PHP PHP XML Parser PHP Zip เขตเวลา PHP

ฟังก์ชันนิพจน์ทั่วไป ของ PHP


PHP Regular Expression Introduction

นิพจน์ทั่วไปช่วยให้คุณค้นหาและแทนที่รูปแบบในสตริงได้


การติดตั้ง

ฟังก์ชันนิพจน์ทั่วไปของ PHP เป็นส่วนหนึ่งของแกน PHP ไม่จำเป็นต้องติดตั้งเพื่อใช้ฟังก์ชันเหล่านี้


การกำหนดค่ารันไทม์

การตั้งค่าเหล่านี้ใน php.ini สามารถใช้เพื่อจำกัดเวลาหรือทรัพยากรที่ใช้ในการประเมินนิพจน์ทั่วไป

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

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

ตัวแก้ไขนิพจน์ทั่วไป

ตัวปรับแต่งสามารถเปลี่ยนวิธีดำเนินการค้นหาได้

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

รูปแบบนิพจน์ทั่วไป

วงเล็บถูกใช้เพื่อค้นหาช่วงของอักขระ:

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

เมตาคาแรคเตอร์

Metacharacters เป็นอักขระที่มีความหมายพิเศษ:

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

ปริมาณ

ปริมาณกำหนดปริมาณ:

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

หมายเหตุ:หากนิพจน์ของคุณต้องการค้นหาอักขระพิเศษตัวใดตัวหนึ่ง คุณสามารถใช้แบ็กสแลช ( \ ) เพื่อหลีกหนีจากอักขระเหล่านั้น ตัวอย่างเช่น หากต้องการค้นหาเครื่องหมายคำถามตั้งแต่หนึ่งเครื่องหมายขึ้นไป คุณสามารถใช้นิพจน์ต่อไปนี้: $pattern = '/\?+/';