Can not figure out preg_replace syntx

Hello Guru’s,

I am trying to echo a string named $usersname.
Often $usersname has an ‘’ appended to the end which I need to eliminate.
I currently use strpos() but I thought preg_replace would be better.
How can I echo $usersname without the '
’ on the end, when it has one.
For example: $username = John Doe*
I want to display only: John Doe


You probably don’t need to use a regex unless you want to keep asterisks that are not on the end. If you don’t, just use
If you do, use
if (substr($username),-1) == '
If there are multiple asterisks and you don’t want any of them, encase the previous code in a [tt]while[/tt] loop, like this:
while(substr($username),-1) != ‘*’){
Hope it works!

Thanks for your suggestions.

Sponsor our Newsletter | Privacy Policy | Terms of Service