arfa Posted November 10, 2008 Share Posted November 10, 2008 A simple one? -- for those that know how. I am trying to strip everything from a string that is NOT a-z, 0-9 I started with: ereg_replace("[^a-z0-9]",'',$string); Tried various other permutations. Oh dear... What should I be doing? thanks - arfa Quote Link to comment Share on other sites More sharing options...
nrg_alpha Posted November 10, 2008 Share Posted November 10, 2008 I would recommend not using ereg, as of PHP6, it will not be supported in the core by default (I think it will only be an extension). You should use preg instead. Here is a good starter thread for that. You can also read about PCRE regex here. $str = 'testing 123...'; $str = preg_replace('#[^a-z0-9]#', '', $str); echo $str; Ouput: testing123 Quote Link to comment Share on other sites More sharing options...
arfa Posted November 13, 2008 Author Share Posted November 13, 2008 thanks for the heads up on php6 Generally there seems to be a very slow uptake of php5 And, thanks for the str = str works just fine. Quote Link to comment Share on other sites More sharing options...
nrg_alpha Posted November 13, 2008 Share Posted November 13, 2008 Generally there seems to be a very slow uptake of php5 Well, PHP 5.3 is now in alpha.. so once that final stable release launches, I assume 6 is next. I personally am not concerned with how long it takes, so long as each version is developed properly with the least amount of bugs possible while adding robust features. So yes, it may take a while till version 6 finally arrives.. but it's best to future proof your code now.. that way, when version 6 does arrive, your php scripts will not 'mysteriously' break on you. Cheers, NRG Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.