Forums »
  Wallpaper Scripts Forums And Topics About Programming »
    How To Remove Numbers From A String Php

How To Remove Numbers From A String Php

Description: How To Remove Numbers From A String Php
Tags: how ,to ,remove ,numbers ,from ,a ,string ,php
Posted On Thu Feb 14, 2008 By hostman In Wallpaper Scripts Forums And Topics About Programming Forums
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 -
www.echteinfach.tv Sun Nov 27, 2011
Use regex in php: trim(str_replac 23 PM'));

greetin
Corne Thu Nov 03, 2011
preg_replace('/[^0-9]/i', '', $string) does the oppostite in this insatnce it will retain the numerics as it will retain the alpha characters if you change it to preg_replace('/[^a-z]/i', '', $string) where it will throw away all other characters except the alpha characters.
DON Sat Sep 03, 2011
because it does not work.. did your try it?
Jason Sat Aug 08, 2009
why not use regular expressions? for example:
$string = preg_replace('/[^a-z]/i', '', $string);
will remove everything except a-z (and a-z of course since /i = case insensitive).
Pradeep Mon May 11, 2009
it's really very good post. very helpful function. please keep it up.
downloadfreephpscripts

download free php scripts team
elpedro Thu Nov 27, 2008
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!

Information
Title: How To Remove Numbers From A String Php
Info: This Post Has Been Viewed 0 Times Since
Date: Thu Feb 14, 2008
Author hostman Received 6 Replies #1327
Related Content
Related Pages
Related Sites
Add Your Website
Share
wallpaperama | Wallpapers | Forums | Terms Of Service

copyright © 2013 wallpaperama - All Rights Reserved - Last Updated Wed Jun 19, 2013 (-8 GMT)
Powered by: Webune Forums V5