Found the answer.

function clean_string( $string )
{
      return trim( ereg_replace( "[^[:space:]a-zA-Z0-9_-]", " ", $string ) );
}

is what does the trick for me.

Thanks

On 4/26/06, Gerry Danen <[EMAIL PROTECTED]> wrote:
> Hi Michael,
>
> And if I want to keep, say a dash, would that become
> ereg_replace("[^\-A-Za-z0-9]", " ", $string) ?
>
>
> On 4/26/06, Michael Roush <[EMAIL PROTECTED] > wrote:
> >
> > --- Gerry <[EMAIL PROTECTED]> wrote:
> >
> > > I would like to replace all chars in a string that are not a-z or 0-9
> > > with a space. I can use a series of str_replace functions, but there
> > > has to be a faster way.
> >
> >
> > Use one ereg_replace function.
> >
> > Where $string is the string you mention....
> >
> > ereg_replace("[^a-z0-9]", " ", $string)
> >
> > This will replace all characters that are not a-z or 0-9 (including
> > spaces!) with a space.
> >
> > Notice, this will also replace any uppercase letters (A-Z) with a space.
> > If you want uppercase letters to be left alone, use the following:
> >
> > ereg_replace("[^A-Za-z0-9]", " ", $string)
> >
> > Rationale: The [] square brackets indicate a set of possible matches to be
> > searched for.  The ^ carat at the beginning indicates "not any of these".
> >
>
> --
> Gerry
> http://dev.danen.org/


--
Gerry
http://dev.danen.org/


The php_mysql group is dedicated to learn more about the PHP/MySQL web database possibilities through group learning.



YAHOO! GROUPS LINKS




Reply via email to