Jump to content


Photo

need a little help here!!!


  • Please log in to reply
2 replies to this topic

#1 wiegs

wiegs
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 17 March 2006 - 03:42 AM

I need to figure out a way to extract only numberic data from one field into another.

original data:
test2345.gif


results I would like:
2345

please help! I have spent way to much time trying to figure this out.


#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 17 March 2006 - 03:50 AM

Something like this should work:

$s = "test2345.gif";

function getnumbers($str) {
    $ret = "";
    for ($i = 0; $i <= strlen($str); $i++) {
        if (is_numeric($str{$i})) {
            $ret .= $str{$i};
        }
    }
    return $ret;
}

echo getnumbers($s);


#3 wiegs

wiegs
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 17 March 2006 - 04:09 AM

[!--quoteo(post=355806:date=Mar 16 2006, 09:50 PM:name=hitman6003)--][div class=\'quotetop\']QUOTE(hitman6003 @ Mar 16 2006, 09:50 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Something like this should work:

$s = "test2345.gif";

function getnumbers($str) {
    $ret = "";
    for ($i = 0; $i <= strlen($str); $i++) {
        if (is_numeric($str{$i})) {
            $ret .= $str{$i};
        }
    }
    return $ret;
}

echo getnumbers($s);
[/quote]


this worked great. thanks!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users