how to remove numbers from a string php

RegisterLogin
how to remove numbers from a string php
Post Description: how to remove numbers from a string php
Tags: how, to, remove, numbers, from, a, string, php
This Post Was Posted On Oct 01, 2009 By web hosting #1862
lets say you have a string in a form and you want to delete all the numbers from the value of that string. well, today, i will show you..
you can use this function
CODE:
<?php
	# FUNCTION BY WWW.WEBUNE.COM
	function remove_numbers($string) {
  		$vowels = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "0", " ");
  		$string = str_replace($vowels, '', $string);
  		return $string;
  	}
	$string='This string will have all numbers removed - 213 555 3930';
	echo remove_numbers($string);
?>

this will remove all the numbers from the variable string
OUTPUT:
This string will have all numbers removed -
Leave Your Comments
AXXIS
#4934 1
why not use regular expression?
$string = preg_replace('/[^a-z]/i', '', $string);

will do exactly the same thing and match faster too!
Mar 21, 2011 Reply Report abuse
James
#4715 2
i used this code to check whether or not a telephone number was valid. take the number, remove all numbers from it, if strlen($number) > 0, then they obviously entered a bogus number. pretty handy. and rather funny that the numbers are "vowels"
Dec 23, 2010 Reply Report abuse
loulou2
#2789 3
can you show me how to use php so i can strip numbers out of strings?
Nov 10, 2009 Reply Report abuse
kanza
#2703 4
my questions is how to you make php return all numbers in a string
Nov 04, 2009 Reply Report abuse
sloloman
#2480 5
i tried it, and it works.

fantastic! greate work
Oct 01, 2009 Reply Report abuse
chilippeper
#2101 6
thanks for helping with remove numbers from a string in php.

does anyone have uses for this functions.?

if so, please let me know, i have modify it to make it better
Jul 17, 2009 Reply Report abuse
Leave Your Comments...
©2011 Webune Forums - Mon Dec 19, 2011 7:15 am
Powered by: Webune Forums V3