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/
[Non-text portions of this message have been removed]
The php_mysql group is dedicated to learn more about the PHP/MySQL web database possibilities through group learning.
SPONSORED LINKS
| American general life and accident insurance company | American general life insurance company | American general life |
| American general mortgage | American general life insurance | Computer internet security |
YAHOO! GROUPS LINKS
- Visit your group "php_mysql" on the web.
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
