php 函数preg_match、preg_match_all ,以及正则表达式规则

<?php
$str = 'php is the best language phhhhp is';
$part = '/ph{1,}p/';
echo preg_match($part, $str,$ar1);
var_dump($ar1);
echo preg_match_all($part, $str,$ar);
var_dump($ar);
echo $ar[0][0];



1
array
  0 => string 'php' (length=3)
2
array
  0 => 
    array
      0 => string 'php' (length=3)
      1 => string 'phhhhp' (length=6)
php

  

php比较两个数组不同元素 函数array_diff:

常用函数:

$a = array('a','b','c');
$b = array('a','b','d');
$c = array_diff($a,$b);

$d = array_diff($b,$a);

打印:

$c = array('c');

$d = array('d');

php正则表达式:

http://deerchao.net/tutorials/regex/regex-1.htm

需要转义字符:

  .  *  ^  &  [  ]  {  }  ?

 

原文地址:https://www.cnblogs.com/lola/p/5437088.html