Jump to content

[SOLVED] Only allow Certain Characters


limitphp

Recommended Posts

I only want to allow certain characters in a string.  But, if they have a character that isn't allowed, I want to replace it with nothing.

 

So, instead of using a str_replace() and typing in all the characters that are invalid, I would like to check to see if the characters are valid, and then if they are not, replace them with nothing.

 

Would I do that by using a preg_replace inside of a str_replace?  Or is that the wrong way to go about it?

 

The only characters I want to allow would be [a-zA-Z0-9 ] all letters and numbers and spaces.

 

Link to comment
https://forums.phpfreaks.com/topic/140832-solved-only-allow-certain-characters/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.