Home > Backend Development > PHP Tutorial > (PHP) Regular expression-Usage of preg_split function

(PHP) Regular expression-Usage of preg_split function

黄舟
Release: 2023-03-04 13:24:01
Original
1708 people have browsed it

<?php
/**
 * Created by PhpStorm.
 * User: Ollydebug
 * Date: 2015/11/15
 * Time: 10:13
 */

//preg_split-升级版explode函数
//preg_split的主要意思是通过一个正则表达式分割字符串

$pattern = &#39;/[0-9]/&#39;;
$subject = &#39;钻3石2星5尘4拳&#39;;

$arr = preg_split($pattern,$subject);

show($arr);

function show($var){
    if(empty($var)){
        echo &#39;null&#39;;
    }elseif(is_array($var)||is_object($var)){
        // array,object
        echo &#39;<pre class="brush:php;toolbar:false">&#39;;
        print_r($var);
        echo &#39;
'; }else{ //string,int,float echo $var; } } ?>
Copy after login

The above is the usage of (PHP) regular expression-preg_split function. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template