Page 1 of 1

Non-Regex function to remove non-alphanumeric characters?

Posted: Tue Nov 04, 2008 3:17 pm
by JAB Creations
Is there a non-regex function to remove non-alphanumeric characters from a string? I'm trying to convert blog tags to be SEO/URL friendly so in example "application/xhtml+xml" is still SEO friendly as "applicationxhtmlxml".

I could do this though I'm wondering if there are any other options?

Code: Select all

$new_string = preg_replace("/[^a-zA-Z0-9]/", "", $string);

Re: Non-Regex function to remove non-alphanumeric characters?

Posted: Tue Nov 04, 2008 3:21 pm
by Jade
Is there a reason why you don't want to use regex?

Re: Non-Regex function to remove non-alphanumeric characters?

Posted: Tue Nov 04, 2008 3:26 pm
by JAB Creations
Load.

Re: Non-Regex function to remove non-alphanumeric characters?

Posted: Tue Nov 04, 2008 3:35 pm
by Jade
I'm not sure you have much alternative. Nothing I can think of anyways. My best suggestion would be to store them after they've been converted instead of replacing every time.

Re: Non-Regex function to remove non-alphanumeric characters?

Posted: Tue Nov 04, 2008 3:49 pm
by JAB Creations
True, I'd rather store an extra column instead of endlessly executing regex over and over. Unless any there are any alternative suggestions that is the route I'll go with for now.