浅析PHP正则表达式函数库
浅析PHP正则表达式函数库是什么呢?这里向你介绍了PHP正则表达式函数库(POSIX 扩展)greedy匹配,我们要注意,在条件子模式以及其它许多 POSIX 扩展正则表达式语法中那些所不被不支持的特性。
PHP正则表达式函数库学习中的警告:
本类正则表达式并不能安全用于二进制模式。PCRE 函数库则可以。正则表达式在 PHP 中用来做复杂的字符串操作。支持正则表达式的函数为:
◆ereg()
◆ereg_replace()
◆eregi()
◆eregi_replace()
◆split()
◆spliti()
这些函数都接受一个正则表达式字符串作为其第一个参数。PHP 使用由 POSIX 1003.3 定义的 POSIX 扩展正则表达式。POSIX 正则表达式完整的描述见包含在 PHP 发行包中 regex 目录下的 man 页面。可以通过类似 man /usr/local/src/regex/regex.7 的命令来阅读。
需求:无需外部库文件就可以加入本扩展模块的支持。
安装警告:除非知道自己在做什么,否则不要改变 TYPE。
要激活 regexp 的支持在配置 PHP 时加上 --with-regex[=TYPE]。TYPE 可以是 system,apache 或 php 之一。默认使用 php。
PHP的Windows 版本已经内置该扩展模块的支持。您无需加载任何附加的扩展库即可使用这些函数。我们来看看具体的相关操作:
◆运行时配置:该扩展模块未定义任何设置指令。
◆资源类型:该扩展模块未定义任何资源类型。
◆预定义常量:该扩展模块未定义任何常量。
PHP正则表达式函数的实例:
<ol class="dp-c"><li class="alt"><span><span><?php </SPAN></span><li> <span class="comment">// 如果在 $string 中任何地方找到 "abc" 则返回 &true; </span><span> </span> </li> <li class="alt"> <span class="func">ereg</span><span> (</span><span class="string">"abc"</span><span>, </span><span class="vars">$string</span><span>); </span> </li> <li><span> </span></li> <li class="alt"> <span class="comment">// 如果 $string 以 "abc" 开头则返回 &true; </span><span> </span> </li> <li> <span class="func">ereg</span><span> (</span><span class="string">"^abc"</span><span>, </span><span class="vars">$string</span><span>); </span> </li> <li class="alt"><span> </span></li> <li> <span class="comment">// 如果 $string 以 "abc" 结尾则返回 &true; </span><span> </span> </li> <li class="alt"> <span class="func">ereg</span><span> (</span><span class="string">"abc$"</span><span>, </span><span class="vars">$string</span><span>); </span> </li> <li><span> </span></li> <li class="alt"> <span class="comment">// 如果用户浏览器是 Netscape 2,3 或 MSIE 3 则返回 &true; </span><span> </span> </li> <li> <span class="func">eregi</span><span> (</span><span class="string">"(ozilla.[23]|MSIE.3)"</span><span>, </span><span class="vars">$HTTP_USER_AGENT</span><span>); </span> </li> <li class="alt"><span> </span></li> <li> <span class="comment">// 将三个空格分隔的单词放入 $regs[1],$regs[2] 和 $regs[3] 中 </span><span> </span> </li> <li class="alt"> <span class="func">ereg</span><span> ("([[:alnum:]]+) ([[:alnum:]]+) </span> </li> <li> <span> ([[:alnum:]]+)", </span><span class="vars">$string</span><span>,</span><span class="vars">$regs</span><span>); </span> </li> <li class="alt"><span> </span></li> <li> <span class="comment">// 将 <br> 标记放到 $string 开头 </span><span> </span> </li> <li class="alt"> <span class="vars">$string</span><span> = </span><span class="func">ereg_replace</span><span> (</span><span class="string">"^"</span><span>, </span><span class="string">"<br>"</span><span>, </span><span class="vars">$string</span><span>); </span> </li> <li><span> </span></li> <li class="alt"> <span class="comment">// 将 <br> 标记放到 $string 结尾 </span><span> </span> </li> <li> <span class="vars">$string</span><span> = </span><span class="func">ereg_replace</span><span> (</span><span class="string">"$"</span><span>, </span><span class="string">"<br>"</span><span>, </span><span class="vars">$string</span><span>); </span> </li> <li class="alt"><span> </span></li> <li> <span class="comment">// 删除 $string 中的所有换行符 </span><span> </span> </li> <li class="alt"> <span class="vars">$string</span><span> = </span><span class="func">ereg_replace</span><span> (</span><span class="string">"n"</span><span>, </span><span class="string">""</span><span>, </span><span class="vars">$string</span><span>); </span> </li> <li><span>?> </span></li></span></li></ol>
PHP正则表达式函数相关的介绍就向你介绍到这里,希望对你了解和学习PHP正则表达式函数有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7
