guestabc1 Posted June 2, 2010 Share Posted June 2, 2010 Hi I have come across a problem with my code since upgrading to php version 5.03 that ereg_replace can no longer be used, instead it is my understanding that I have to use preg_replace? If someone could point me in the right direction with the following code it would be hugely appreciated! Thanks in advance! function format_strng($strng) { $invalid_chars = '[^A-Za-z0-9+_.!*(),-]'; $repeated_chars = '-{2,}'; return strtolower(preg_replace($repeated_chars, '-', preg_replace($invalid_chars, '-', $strng))); } Quote Link to comment Share on other sites More sharing options...
pornophobic Posted June 2, 2010 Share Posted June 2, 2010 preg_replace() Quote Link to comment Share on other sites More sharing options...
beta0x64 Posted June 2, 2010 Share Posted June 2, 2010 First, this should probably go in the PHP Regex section. Second, you need to add delimiters to the regex. Like this: $invalid_chars = '/[^A-Za-z0-9+_.!*(),-]/'; $repeated_chars = '/-{2,}/'; Third, you probably also want to add a + or * to the character class in $invalid_char. And finally, http://www.php.net/manual/en/reference.pcre.pattern.posix.php Have fun. Quote Link to comment Share on other sites More sharing options...
guestabc1 Posted June 2, 2010 Author Share Posted June 2, 2010 Thank you so much for the fast response! I was putting the delimiters in all sorts of places! Much appreciated! 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.