tibberous Posted December 23, 2007 Share Posted December 23, 2007 I am trying to strip out everything from a string except letters, numbers, periods and forward slashes. I figure this will help prevent me a little bit from attacks. Now, this works: $uri = preg_replace("/[^A-Za-z0-9\-\.\/]/", '', $uri); But it that going to be really bad performance wise? Quote Link to comment Share on other sites More sharing options...
dsaba Posted December 24, 2007 Share Posted December 24, 2007 performance is measured in comparison to something... to what you would like to compare this too? I don't know.. Run some performance tests in a loop with str_replace.. or whatever it is you'd like to compare it too and find out. Generally speaking though, it depends on the amount of data you are running the regex through, even still, preg is fast. BTW: Your regex will also strip the spaces from a string. Try: /[^A-Za-z0-9\-\.\/ ]/ <a href="http://nancywalshee03.freehostia.com/regextester/regex_tester.php?seeSaved=ukbjrqpe">Tested here.</a> 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.