php regex for this number to detacted

Discussion in 'PHP' started by ironmankho, Sep 14, 2011.

  1. #1
    please any php expert can write regex for below code
    Thanks

    \n\n(\n\n46320\n\n)
    \n\n(\n\n52556\n\n)
    \n\n(\n\n46320\n\n)
     
    Solved! View solution.
    ironmankho, Sep 14, 2011 IP
  2. fortehlolz

    fortehlolz Banned

    Messages:
    111
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    preg_replace("/\D/","", $input); 
    PHP:

    The "D" is just for "D"igits.
     
    fortehlolz, Sep 14, 2011 IP
  3. #3
    or even just 5 digits

    
    <?php
    
    
    $string = '
    
    \n\n(\n\n46320\n\n)
    \n\n(\n\n52556\n\n)
    \n\n(\n\n46320\n\n)
    
    ';
    
    $do_this = preg_match_all("/(\d{5})/", $string, $match);
    foreach ($match[1] as $ht){
      echo $ht . "<br />";
    }
    ?>
    
    PHP:
     
    MyVodaFone, Sep 14, 2011 IP
  4. ironmankho

    ironmankho Active Member

    Messages:
    393
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #4
    Thanks MyVodaFone can you please convert into php function ?
     
    ironmankho, Sep 14, 2011 IP
  5. fortehlolz

    fortehlolz Banned

    Messages:
    111
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Ah, nicely done. Anyway: function

    
    function number($input) {
      $do_this = preg_match_all("/(\d{5})/", $input, $match);
        foreach ($match[1] as $ht){
        echo $ht . "<br />";
      } 
     }
    
    echo number('    \n\n(\n\n46320\n\n)
            \n\n(\n\n52556\n\n)
            \n\n(\n\n46320\n\n)
            
        ');
    
    PHP:
     
    fortehlolz, Sep 14, 2011 IP