Skip to content

Instantly share code, notes, and snippets.

@leavyli
Last active March 2, 2018 15:24
Show Gist options
  • Select an option

  • Save leavyli/41203f8f291db792d079db0c974dd958 to your computer and use it in GitHub Desktop.

Select an option

Save leavyli/41203f8f291db792d079db0c974dd958 to your computer and use it in GitHub Desktop.

Revisions

  1. leavyli renamed this gist Mar 2, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. leavyli created this gist Mar 2, 2018.
    12 changes: 12 additions & 0 deletions .php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    <?php
    //输出结果string(115) "mobile: 13929****47,13929****47,13929****47,13929****47,1****3,13929****47,13929****47, name:liwei, moblie: 1****6"
    $s = "mobile: 13929571847,13929527847,13929517847,13929575847,123,13929575847,13929575847, name:liwei, moblie: 12636";
    $p =[
    "/(.*?)(\d)(\d{1,4})(\d{1,2},)/",
    "/(.*?)(\d)(\d{1,4})(\d{1,2}$)/",
    ];
    $r = [
    '\1\2****\4',
    '\1\2****\4',
    ];
    $res = preg_replace($p, $r, $s);