Jump to content

ereg_replace


arfa

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.