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

Thanks
Frankie

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
[php]str_replace(’’.’’.$username)[/php]
If you do, use
[php]
if (substr($username),-1) == '
’){
substr_replace($username,’’,-1);
}
[/php]
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:
[php]
while(substr($username),-1) != ‘*’){
substr_replace($username,’’,-1);
}
[/php]
Hope it works!

Thanks for your suggestions.

Sponsor our Newsletter | Privacy Policy | Terms of Service