str="在123"
str1=""
for i=1 to len(str)
   char1=mid(str,i,1)
   if IsNumeric(char1) then str1=str1&char1
next

解决方案 »

  1.   

    情况一:提取一组数字<?php
    $reg_str = "/([\d]+)/";
    $str = "在123中提取数字";
    preg_match($reg_str,$str,$matchs);
    echo $matchs[1];
    ?>
    //输出:123情况二:提取多组数字<?php
    $reg_str = "/([\d]+)/";
    $str = "在123和456中提取数字";
    preg_match_all($reg_str,$str,$matchs);
    print_r($matchs[1]);
    ?>
    //输出:
    Array
    (
        [0] => 123
        [1] => 456
    )
      

  2.   

    <?
    /*
    笨办法,ereg函数对 /[一二三]/ 支持的不好。。
    */
    $str = "一看看二,,,三看看";
    $res = "";
    $arr = array("一","二","三","四","五","六","七","八","九","十");foreach($arr as $k => $v)
    {
    if(preg_match("/$v/",$str))
    $res .= "$v";
    }
    print $res;
    ?>
      

  3.   


    <?php
    $reg_str = "/([零一二三四五六七八九十]+)/";
    $str = "在 一二三 中提取中文数字";
    preg_match($reg_str,$str,$matchs);
    print_r($matchs[1]);
    ?>
    //输出:一二三原来是要这样的
      

  4.   

    把str的半角空格去了 就有bug了=。= 随便打了个 $str = "在的一的二的三的中提取中文数字";  出来的是“囊”字呵呵。
      

  5.   

    ereg函数组是按单字节判断 
      

  6.   

    实际测试(zend studio) str="在的一的二的三的中提取中文数字" 输出的是"一",请问 出来"囊"是用什么开发环境?
      

  7.   

    notpad + phpPHP 5.2.4 (cli) (built: Aug 30 2007 07:06:31)
    Copyright (c) 1997-2007 The PHP Group
    Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies