$str1="北京(55,42)";=》55042
$str2="上海(等级7)(137,238)";==》137238
$str3="杭州(等级1)(137,38)";==》137038$str4="老外(等级1)(1,1)";==》1001
坐标为三位的,总共6位,怎样取到坐标呢,坐标从1开始

解决方案 »

  1.   


    <?
    $str1="北京(55,42)";
    $str2="上海(等级7)(1,238)";
    $a=explode('(',strrchr($str2,'('));
    $b=explode(')',$a[1]);
    $c=explode(',',$b[0]);
    if(strlen($c[0])==3)
    {
    echo $c[0].$c[1];
    }
    else
    {
    if(strlen($c[0])==2)
    {
    echo $c[0].'0'.$c[1];
    }
    else 
    {
    echo $c[0].'00'.$c[1];
    }
    }我写的有点慢 别急呀
      

  2.   


    <?php
    function getstrnum($str) {
      preg_match('/(\d*),(\d*)/',$str,$r);
      return $r[1].substr('00'.$r[2], -3);
    }
    echo getstrnum("北京(55,42)")."<br>";
    echo getstrnum("上海(等级7)(137,238)")."<br>"; 
    echo getstrnum("杭州(等级1)(137,38)")."<br>";
    echo getstrnum("老外(等级1)(1,1)")."<br>";
    ?>
      

  3.   

    $last=strrpos($cid,'(');
    $last2=strrpos($cid,')');
    $last3=strrpos($cid,',');
    $x=0;
    $j=1;
    for ($i=$last2-1;$i>$last3;$i--)
    if ($cid[$i]!=',')
    {
    $x+=$cid[$i]*$j;
    $j=$j*10;
    }
    $k=1000;
    for ($i=$last3-1;$i>$last;$i--)
    if ($cid[$i]!=',')
    {
    $x+=$cid[$i]*$k;
    $k=$k*10;
    }
    echo $x
      

  4.   

    你的头像不错,哈哈,抽空写了一个,看这个咋样
    <?php
    $str1="北京(55,42)";//=》55042
    $str2="上海(等级7)(137,238)";//==》137238
    $str3="杭州(等级1)(137,38)";//==》137038$str4="老外(等级1)(1,1)";//==》1001 $pattern    = '/\d{1,}[,]{1}\d{1,}/';
    $str        = '';
    function match($string) {
        global $pattern;
        $newstr = preg_replace_callback($pattern,'test', $string);    return $newstr;
    }
    function test($match){
        global $str;
        $newarr = explode(',', $match[0]);
        if ( is_array($newarr) ) {
            $str    .= $newarr[0].sprintf("%03d", $newarr[1])."<br />";
        }
        print_R("<br />");    
    }
    match($str1);
    match($str2);
    match($str3);
    match($str4);
    print_R($str);
    exit;
    ?>