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 -
Comments and replies About how to remove numbers from a string php
elpedro:
you can also remove text instead of numbers, just switch the numbers in
$vowels = array("y", "z", "3", "4", "4", "3", "z", "y", "x", "x", " "); to
$vowels = array("a", "b", "c", "d", "e", f", "g"," "); etc.
note:
if you wan't big letters for this function don't forget that you will need to verify this to the function like this:
$vowels = array("a", "b", "c", "d", "e", f", "g","a","b","c", "d" " "); etc.
great function!
Pradeep:
it's really very good post. very helpful function. please keep it up.
downloadfreephpscripts
download free php scripts team