The Arcive of vBulletin Modifications Site. |
|
Apostrophes Details »»
|
|||||||||||||||||||||||||
Can anyone please help me with the following problem?
I have a user whose name ends with an apostrophe (i.e Bonet'). I want to make the name with an s like this (for ownership) Bonet's instead of Bonet''s with 2 apostrophes. I am using $userinfo[username] to get the name and if I use an 's for ownership on all other names it appears fine. I need to have it not add an apostrophe after the name if one is already there, just the s, but still keep the 's for all other names. I know it sounds confusing. I'm not sure how to pull the information out of the username variable to do this. Can anybody help?Show Your Support
|
|||||||||||||||||||||||||
| Comments |
|
#2
|
|||
|
|||
|
em you could use a regexp but simpliest way is
if(substr($userinfo['username'], -1) == '\\'') { $userinfo['username'] .= 's'; } else { $userinfo['username'] .= '\\'s'; } |
|
#3
|
||||
|
||||
|
Scott, that works perfect. As a matter of fact, it works too perfect. Is there a way I can use a variable after the users name (like $s) instead so I can just use it where I need it and not have it show up where I don't?
![]() BTW: What is a regexp? Just curious. ![]() Quote:
|
|
#4
|
||||
|
||||
|
Here's what I came up with. It seems to work. Is it right? And thank you, Scott.
![]() Quote:
|
|
#5
|
||||
|
||||
|
<a href="http://php.fastmirror.com/manual/en/ref.pcre.php" target="_blank">http://php.fastmirror.com/manual/en/ref.pcre.php</a>
|
|
#6
|
|||
|
|||
|
could use
Quote:
|
|
#7
|
||||
|
||||
|
Ok, one last question, please. And thank you for all of the help on this. I really appreciate it.
![]() Is there a way to do it globally for any username variable (i.e. $bbuserinfo[username] and $userinfo[username] and $post[username]) instead of having to do it individually in each area and with each different username variable? And thank you for the link, Chen. I will check it out.
|
|
#8
|
|||
|
|||
|
you could just make a function
function doapostrophe($username) { if (preg_match ("(\\'$)", $username)) { $username .= 's'; } else { $username .= '\\'s'; } return $username; } and when you need to just use $userinfo['username'] = doapostrophe($userinfo['username']); something like that? |
|
#9
|
||||
|
||||
|
That sounds like what I am looking for. But would there be a way to make it with the $a variable so I could just add the $a where I needed it instead of having to do the doapostrophe all over the site? And I could put this anywhere in the functions.php and it would work site wide, right? Or do I need to put it a certain place in there?
Quote:
|
|
#10
|
|||
|
|||
|
You could just use
$userinfo['usernames'] = doapostrophe($userinfo['username']); and just user $userinfo['usernames'] where you want it with the s at the end. Correct anywhere in functions.php |
![]() |
|
|