Page 1 of 1
how to manipulate text ?
Posted: Tue Feb 09, 2010 4:07 pm
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
Re: how to manipulate text ?
Posted: Tue Feb 09, 2010 6:32 pm
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.
Re: how to manipulate text ?
Posted: Wed Feb 10, 2010 1:41 am
by klevis miho
$vendorname = $_POST['vendorname'];
//removes spaces, and lowers cases
$vendorname = strtolower(trim(str_replace(' ', '', $vendorname)));
//removes numbers
ereg_replace("[0-9]", "", $vendorname);
Re: how to manipulate text ?
Posted: Wed Feb 10, 2010 6:35 am
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