$str="we have 10 students,20 classes,70 houses.";
preg_match_all("/we have (\d+) students,(\d+) classes,(\d+) houses/iU", $str, $array)
echo "<pre>";
print_r($array);换不同数字测试一下,看明白$array的结构,自己把对应变量赋值

解决方案 »

  1.   

    preg_match_all:
    <?php
    preg_match_all ("|<[^>]+>(.*)</[^>]+>|U",
        "<b>example: </b><div align=left>this is a test</div>",
        $out, PREG_PATTERN_ORDER);
    print $out[0][0].", ".$out[0][1]."\n";
    print $out[1][0].", ".$out[1][1]."\n";
    ?>
      

  2.   

    <?php
    $str="we have 10 students,20 classes,70 houses.";
    preg_match_all("/\d+/", $str, $array);
    print_r($array);
    ?>Array
    (
        [0] => Array
            (
                [0] => 10
                [1] => 20
                [2] => 70
            ))