how can i clean chrs that are not numbers and live only numb

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

how can i clean chrs that are not numbers and live only numb

Post by pelegk2 »

i have this string :
"5d2e1fe"
and i want to get only : "521"
how can i do it?
thanks in advance
peleg
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You could use [php_man]preg_replace[/php_man]():

Code: Select all

$text_and_numbers = '5d2e1fe';
$just_numbers = preg_replace('/[^0-9]/', '', $text_and_numbers);

echo $just_numbers;
Mac
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

P.S. Is this directly related to this:
viewtopic.php?t=15665

Mac
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

yepppp
Post Reply