Reputation: 291
How does one remove all non-alphanumeric characters at the end of a string. Eg:
Quick @# brown fox -
Quick @# brown fox##
Quick @# brown fox
Quick @# brown fox @$#
all become
Quick @# brown fox
Seeking to possibly use preg_replace
because ereg_replace
is deprecated.
It could also be tweaked to allow specific non-alphanumeric characters at end of string, eg quotes, exclamation marks, question marks
Upvotes: 0
Views: 3137
Reputation: 9703
$str = 'Quick @# brown fox @$#';
$rep = preg_replace('/[^a-z0-9]+\Z/i', '', $str);
var_dump($rep);
Upvotes: 6