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))); } Link to comment https://forums.phpfreaks.com/topic/203680-help-changing-from-ereg_replace-to-preg_replace/ Share on other sites More sharing options...
pornophobic Posted June 2, 2010 Share Posted June 2, 2010 preg_replace() Link to comment https://forums.phpfreaks.com/topic/203680-help-changing-from-ereg_replace-to-preg_replace/#findComment-1066827 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. Link to comment https://forums.phpfreaks.com/topic/203680-help-changing-from-ereg_replace-to-preg_replace/#findComment-1066828 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! Link to comment https://forums.phpfreaks.com/topic/203680-help-changing-from-ereg_replace-to-preg_replace/#findComment-1066832 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.