Jump to content


Photo

REPLACE


  • Please log in to reply
2 replies to this topic

#1 mafkeesxxx

mafkeesxxx
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 08 September 2006 - 10:17 AM

Hi!

I have a string here:

$_SERVER['LOGON_USER']

Now, this displays the "current logged on user"

Now i want to translate these usernames into realnames.

Something like:

username1 = Alpha
username2 = Bravo
username3 = Charlie

I can use str_replace, but then it works only for one username, is it possible to make a code to do this for more then one username?

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 08 September 2006 - 10:21 AM

Sure, using arrays :)

Here's an example:
<?php


$usernames=array("User1","User2","User3");

$replacement=array("Alpha","Bravo","Charlie");

$user=str_replace($usernames,$replacement,$$user);


?>

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 mafkeesxxx

mafkeesxxx
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 08 September 2006 - 12:19 PM

Sure, using arrays :)

Here's an example:

<?php


$usernames=array("User1","User2","User3");

$replacement=array("Alpha","Bravo","Charlie");

$user=str_replace($usernames,$replacement,$$user);


?>

Orio.


GREAT!!!

Thanks dude. This was exactly what i needed!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users