(1)perl格式的
$str="42,53,56十二码,31,-76十二码,80,90,4,-49,21,90,6,-49,88,90,21,50十二码,75,25,83,36十二";
$str=",".$str;
preg_match_all("/,(\d\d*)/",$str,$arr);
echo "<pre>";
print_r($arr);
echo "</pre>";

解决方案 »

  1.   

    呵呵,这里重复了,改作
    preg_match_all("/,(\d+)/",$str,$arr);
    更简单一些。
      

  2.   

    谢谢goodname 我自己要好好学习正则表达式了
      

  3.   

    根据习惯优化了一下,写成函数了,更好用一些,正则表达式没有什么变化。<?php
    /*  BEGIN function  功能:获得匹配的字符串
    编写时间:2003.7.14
    编写人:
    变量:$str
    返回值:string
    */
    function matchstr($str) {
    global $total;
    $str=",".$str;
    preg_match_all("/,(\d+)/",$str,$arr);
    for($i=0; $i<count($arr[0]); $i++) {
    $total[$i].= $arr[0][$i];
    }
    Return $total;
    }
    /*  END function *///调用
    $str="42,53,56十二码,31,-76十二码,80,90,4,-49,21,90,6,-49,88,90,21,50十二码,75,25,83,36十二";
    $string=matchstr($str);//返回的数组赋给一个变量$string//以后想怎么办就怎么办吧 ^_^/*
    for($i=0; $i<count($string); $i++) {
    $str_all.=$string[$i];
    }
    $array=explode(',',$str_all);
    for($j=1; $j<count($array); $j++) {
    $getstring.=$array[$j].',';

    }echo "$getstring";
    */
    ?>
      

  4.   

    我写了一个 核心技术用了gooodname的 帖子暂时不结 请大家斧正function process_string($string)
     {
       //$string = ",".$string;
       $string = preg_replace("/\,+/",",",$string); 
       $string = preg_replace("/^\,/","",$string); 
       $string = preg_replace("/\,$/","",$string); 
       preg_match_all("/,(\d+)/",$string,$arr);
       
        while (list($v ,$a) = each($arr[1]))
     {
        $string_arr[] = $a;
     }
        reset($string_arr);
        return $string_arr;
     }
      

  5.   

    呵呵,这样就可以,函数未作容错处理。function match_str($str)
    {
    preg_match_all("/,(\d+)/",",".$str,$arr);
    return $arr[1];
    }
    $str="42,53,56十二码,31,-76十二码,80,90,4,-49,21,90,6,-49,88,90,21,50十二码,75,25,83,36十二";
    $arr=match_str($str);
    echo "<pre>";
    print_r($arr);
    echo "</pre>";
      

  6.   

    函数返回一个数组
    得到字符串可以使用
    $str=implode(",",$arr); //可以得到一个用,分隔的字符串
    $arr=explode(",",$str);//把用,隔开的字符串切割成一个数组
      

  7.   

    根据xuzhuning的指导,这么作,最佳:
    function match_str($str)
    {
    preg_match_all("/(?=^|,),?(\d+)/",$str,$arr);
    //preg_match_all("/(?=^|,),?((?:--)*\d+)/",$str,$arr);
    return $arr[1];
    }
    $str="42,53,56十二码,31,-76十二码,80,90,4,-49,21,90,6,-49,88,90,21,50十二码,75,25,83,36十二";
    $arr=match_str($str);
    echo "<pre>";
    print_r($arr);
    echo "</pre>";
    exit;
    我这么认为的,不知道还有没有更好的做法
      

  8.   

    Warning: Failed opening 'E:\www\xmltest\1.php' for inclusion (include_path='c:\php4\pear') in Unknown on line 0这个什么错误