Home  >  Article  >  Backend Development  >  PHP regex - ignore whitespace

PHP regex - ignore whitespace

WBOY
WBOYOriginal
2016-07-29 09:11:511410browse
<?php
/**
 * Created by PhpStorm.
 * User: Ollydebug
 * Date: 2015/11/15
 * Time: 15:20
 */

/*
 * U-懒惰匹配
 * i-忽略英文字母大小写
 * x-忽略空白
 * s-让元字符&#39; . &#39;匹配包括换行符内所有字符
 */

$pattern = &#39;/Go   Ogle.+123/Uix&#39;;
$subject = &#39;I love google__123123123123123123&#39;;

$matches = array();
preg_match($pattern,$subject,$matches);

show($matches);

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">';
        print_r($var);
        echo '
'; }else{ //string,int,float echo $var; } } ?>

The above introduces PHP regular expressions - ignore the blanks, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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