


(PHP) Regular expression-usage of preg_match and preg_match_all()
<?php /** * 正则表达式练习 * User: Ollydebug * Date: 2015/11/13 * Time: 13:28 */ /* * preg_match()第三个参数可选,第三个参数是引用传递,它在匹配subject的时候,只会匹配一次 * preg_match_all()第三个参数必填,第三个参数也是引用传递,它在匹配subject的时候,会把所有满足条件的结果都匹配出来 */ $pattern = '/[0-9]/'; $subject = 'weuyr3ui76as83s0ck9'; $m1 = $m2 = array(); $t1 = preg_match($pattern,$subject,$m1); $t2 = preg_match_all($pattern,$subject,$m2); show($m1); echo '<hr/>'; show($m2); echo '<hr/>'; show($t1.'||'.$t2); function show($var){ if(empty($var)){ echo 'null'; }elseif(is_array($var)||is_object($var)){ // array,object echo '<pre class="brush:php;toolbar:false">'; print_r($var); echo ''; }else{ //string,int,float echo $var; } } ?>
The above is the usage of (PHP) regular expressions-preg_match and preg_match_all(). For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

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











The preg_match_all() function in PHP: How to use regular expressions to match multiple strings, specific code examples are required. Regular expressions are a tool used to describe text patterns. They can be used to match, search, or replace text that matches a certain pattern. Pattern string. The preg_match_all() function in PHP is a very useful function that can match multiple strings using regular expressions. The basic syntax of the preg_match_all() function is as follows: preg_ma

Golang regular expressions use the pipe character | to match multiple words or strings, separating each option as a logical OR expression. For example: matches "fox" or "dog": fox|dog matches "quick", "brown" or "lazy": (quick|brown|lazy) matches "Go", "Python" or "Java": Go|Python |Java matches words or 4-digit zip codes: ([a-zA

PHP regular expressions are a powerful tool for text processing and conversion. It can effectively manage text information by parsing text content and replacing or intercepting it according to specific patterns. Among them, a common application of regular expressions is to replace strings starting with specific characters. We will explain this as follows

How to remove Chinese in PHP using regular expressions: 1. Create a PHP sample file; 2. Define a string containing Chinese and English; 3. Use "preg_replace('/([\x80-\xff]*)/i', '',$a);" The regular method can remove Chinese characters from the query results.

In this article, we will learn how to remove HTML tags and extract plain text content from HTML strings using PHP regular expressions. To demonstrate how to remove HTML tags, let's first define a string containing HTML tags.

PHP regular replacement examples: quickly master replacement skills. With the development of the Internet, website development has become more and more common. In website development, it is often necessary to replace strings, and regular expressions are a very powerful tool that can quickly search and replace strings. This article will introduce how to use regular expressions in the PHP language to perform replacement operations, and provide specific code examples to help readers quickly master replacement techniques. 1.preg_replace function in PHP, you can use preg

Sharing tips on using PHP regular expressions to implement the Chinese replacement function. In web development, we often encounter situations where Chinese content needs to be replaced. As a popular server-side scripting language, PHP provides powerful regular expression functions, which can easily realize Chinese replacement. This article will share some techniques for using regular expressions to implement Chinese substitution in PHP, and provide specific code examples. 1. Use the preg_replace function to implement Chinese replacement. The preg_replace function in PHP can be used

Website security has attracted more and more attention, and using the HTTPS protocol to ensure the security of data transmission has become an important part of current website development. In PHP development, how to use regular expressions to verify whether the URL is HTTPS protocol? here we come to find out. Regular expression Regular expression is an expression used to describe rules. It is a powerful tool for processing text and is widely used in text matching, search and replacement. In PHP development, we can use regular expressions to match http in the URL
