how to manipulate text ?

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
Rippie
Forum Commoner
Posts: 76
Joined: Sun Jan 10, 2010 11:32 am
Location: Nottingham

how to manipulate text ?

Post by Rippie »

Hi all,

Is there an easier way to remove all spaces, non alphabetic and capitals from a string. My code so far is like this.

$vendorname = $_POST['vendorname'];

$vendid = ereg_replace("[^A-Za-z0-9]", "", $vendorname);
$vendorid = strtolower($vendid);

Thx
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: how to manipulate text ?

Post by JakeJ »

other than making that in to a function, I think you're right on target.

Code: Select all

function r_spaces($var){
$var = ereg_replace("[^A-Za-z0-9]", "", $var);
$var = strtolower($vendid);
}
In your original, there is no reason to assign each step to a new variable.
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: how to manipulate text ?

Post by klevis miho »

$vendorname = $_POST['vendorname'];

//removes spaces, and lowers cases
$vendorname = strtolower(trim(str_replace(' ', '', $vendorname)));

//removes numbers
ereg_replace("[0-9]", "", $vendorname);
Rippie
Forum Commoner
Posts: 76
Joined: Sun Jan 10, 2010 11:32 am
Location: Nottingham

Re: how to manipulate text ?

Post by Rippie »

klevis miho wrote:$vendorname = $_POST['vendorname'];

//removes spaces, and lowers cases
$vendorname = strtolower(trim(str_replace(' ', '', $vendorname)));

//removes numbers
ereg_replace("[0-9]", "", $vendorname);
Thx
Post Reply