Help with regex

Discussion in 'PHP' started by linkinpark2014, Oct 19, 2009.

  1. #1
    hi,

    I have this regex:
    preg_match_all("/(Benutzer|Members|Membres|Utenti|Leden|Usuarios|Membros): ([0-9,]*)?/s"
    PHP:
    I have these texts:
    Benutzer: 210,540
    Members: 350,020
    Membres: 403,040
    Utenti: 550,040
    Leden: 600,530
    Usuarios: 370,740
    Membros: 470,071

    I want to get the number of members near the given words..
    so let say if I apply the pattern to the first text it should show this number 210,540

    if I apply it again on the last text it should show 470,071..
    any ideas?
     
    linkinpark2014, Oct 19, 2009 IP
  2. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #2
    following script will extract numbers from the data in array..

    
    <?php
    	
    	$text_array	=	array('Benutzer: 210,540', 'Members: 350,020', 'Membres: 403,040', 'Utenti: 550,040', 'Leden: 600,530', 'Usuarios: 370,740', 'Membros: 470,071');
    	
    	preg_match_all("/(: )([0-9,]*)?/s", implode("\n", $text_array), $matches);
    	
    	print_r($matches[2]);
    	$matches[2] = str_ireplace(',', '', $matches[2]);
    	print_r($matches[2]);
    ?>
    
    PHP:
     
    mastermunj, Oct 19, 2009 IP