Jump to content


Photo

retreive integer from string


  • Please log in to reply
4 replies to this topic

#1 baiju

baiju
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 09 October 2006 - 10:42 AM

hi

how to retrive a only number from string..

$val='3157100325,878042,379,1';
i need only numbers
out shoul be 31571003258780423791;
that means i need only integer values

please help me out

#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 09 October 2006 - 10:44 AM

I think that you want explode. Like this.

$val='3157100325,878042,379,1';
$newval = explode(',', $val);

Hope that helps,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 baiju

baiju
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 09 October 2006 - 10:48 AM

that value contain not only commas may be character also will come
that is problem..

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 09 October 2006 - 12:31 PM

$whatever = "(123) 456-7890";
$whatever_clean = preg_replace('/[^0-9]/','',$whatever);
echo $whatever_clean;

Legend has it that reading the manual never killed anyone.
My site

#5 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 09 October 2006 - 12:45 PM

Had a look at Andy's code works fine.. ill keep it for further reference.. very useful




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users