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
how to manipulate text ?
Moderator: General Moderators
Re: how to manipulate text ?
other than making that in to a function, I think you're right on target.
In your original, there is no reason to assign each step to a new variable.
Code: Select all
function r_spaces($var){
$var = ereg_replace("[^A-Za-z0-9]", "", $var);
$var = strtolower($vendid);
}-
klevis miho
- Forum Contributor
- Posts: 413
- Joined: Wed Oct 29, 2008 2:59 pm
- Location: Albania
- Contact:
Re: how to manipulate text ?
$vendorname = $_POST['vendorname'];
//removes spaces, and lowers cases
$vendorname = strtolower(trim(str_replace(' ', '', $vendorname)));
//removes numbers
ereg_replace("[0-9]", "", $vendorname);
//removes spaces, and lowers cases
$vendorname = strtolower(trim(str_replace(' ', '', $vendorname)));
//removes numbers
ereg_replace("[0-9]", "", $vendorname);
Re: how to manipulate text ?
Thxklevis miho wrote:$vendorname = $_POST['vendorname'];
//removes spaces, and lowers cases
$vendorname = strtolower(trim(str_replace(' ', '', $vendorname)));
//removes numbers
ereg_replace("[0-9]", "", $vendorname);