Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Preg_Replace pattern syntax

Featured Replies

I am trying to use preg_replace to replace all percent encodes (%20, etc) with underscores. I cant figure out the pattern syntax though, it confuses me to no end. Basically, I need it to find all % chars and strip that char, plus the next two char, and replace those three char with an underscore.

 

Anyone got some experience using this pattern system?

  • Author
have you tried using

 

urldecode($theURLyouwishtouse)

 

No, in fact I am using rawURLencode to turn them into these symbols because then I can search by a pattern to find them and delete them. Or I would if I could get the syntax right.

 

 

EDIT: yeah, a good reply! Thank you so much for clarifing. One thing though, the two digits are in hex so 0-9 wont catch the letters...

 

can I use [A-Fa-f0-9] to get it?

 

Edit: I got it working beautifully and I'm cleaning up my code now. Thank you for the help.

  • Author

Here is the finished product.

move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.str_replace(" ", "_", trim(preg_replace('"[^0-9a-z]"'," ",strtolower(substr($_FILES['file']['name'], 0, strrpos($_FILES['file']['name'], ".")))))).strstr($_FILES['file']['name'], "."));

 

It will completely sterilize a file name down to alpha-numeric and underscores for all interior spaces. Any symbols in the name are turned into underscores and no spaces or underscores are left before or after the name. it even removes spaces and symbols from between the extension and the name.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.