Jump to content

Alternative to e pattern modifier in PHP5.5


Go to solution Solved by Jacques1,

Recommended Posts

I have this snippet which is giving a deprecated warning re the "e" pattern modifier in PHP5.5: -

$result = preg_replace("/\[^a-zA-Z0-9]/e"," ",$result);
I'm not even sure what the "e" modifier does, as it's not my code...maybe something to do with removing duplicates?

 

Anyway, what's the best way to replace this so that it doesn't give the warning in PHP5.5, and will work in PHP7.0.0?

 

I've got a feeling this might work :-

$result= preg_replace("/\[^a-zA-Z0-9]/"," ",$result);
but feel I might have over-simplified it, and it maybe doesn't quite do the same thing?

 

Any help much appreciated!

When in doubt, check the manual. Not only does it explain exactly what the modifier does; it also provides alternatives.

 

In your case, the modifier does absolutely nothing. Either it's a leftover from earlier code versions, or the person writing the code was seriously confused.

Thanks for your reply Jacques1.

 

I did check the manual before posting, and it says to use preg_replace_callback() instead. But if, as you say, the modifier in my code does nothing anyway, is my suggestion (i.e. to simply remove it) not the best approach in this case?

Just remove the modifer.

 

The replacement operation itself looks strange, but that's another story.

Thanks again. It's part of a URL building function...to replace any non-alphanumeric characters with spaces, which are in turn replaced with dashes or underscores in the next part...

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.