General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 11th, 2003, 03:41 AM
Vasarab69 Vasarab69 is offline
Goldmember
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 71 Vasarab69 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 25 sec
Reputation Power: 7
Send a message via AIM to Vasarab69
Replacing carat's in account names..

Hi-

I'm coding a site for my online-gaming competitive team... basically, I was curious as to how I could set up a system like the following:

A user registers with the following name: ^0Test^2na^4me

So then, "^0Test^2na^4me" is stored into the database as their username... however, i'd like the name to appear in different colours on the site. i'd obviously use an array of some sort like:

PHP Code:
 $colorscheme = array (

     
"^0" => "black",
     
"^1" => "red",

     ....
etc
     

,

but how could I implement this into the site? I'm also coding basic forums from scratch, and plan on it's implementation with the existing members system. So in the "Author" column, the name would be coloured depending on which carat+number's were used. All help is welcome, thank you.
__________________
-Alexander

Reply With Quote
  #2  
Old October 11th, 2003, 07:17 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 6
Personally I'd make use of the str_replace function -

mixed str_replace ( mixed search, mixed replace, mixed subject [, int &count])

To summarise what this function does -

You give it two arrays and a subject string then it replaces all occurances of items in the first array with items in the second array.

The first array will need to contain your codes -

PHP Code:
 $search = array (
      
'^0',
      
'^1',

       ...
etc); 


The second array will need to contain font tags corresponding to this. Please note the font tags are indeed backwards in this, I'll explain why afterwards.

PHP Code:
 $replace = array (
     
'</font><font color="black">',
     
'</font><font color="red">',

     ...
etc); 


Then you'll need to add a font tag at the start of the string with color set to whatever your default is then a final close font tag at the end.

The font tags appear to be the wrong way around in the second array since each one wants to end the previous one and start a new one at that point.

This approach would also work pecfectly well using div's and classes if you'd prefer that to font tags.

Hope this helps,

-KM-

Reply With Quote
  #3  
Old October 11th, 2003, 04:21 PM
Vasarab69 Vasarab69 is offline
Goldmember
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 71 Vasarab69 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 25 sec
Reputation Power: 7
Send a message via AIM to Vasarab69
Alright, that helped greatly... my only other question is how I would go about allowing them to change colours without changing the actual name.

the database connectivity is rather effective, so if you have an idea, just use an $sql = ""; type thing.... I was thinking of stripping all of the carat+number's from the name and doing a check, or something of that nature. Once again, any help is greatly appreciated .

Reply With Quote
  #4  
Old October 11th, 2003, 05:40 PM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 6
I'm not sure which you're after here. If you want the ^0 ^1 left in then make your array second array something like -

PHP Code:
 $replace = array (
     
'</font><font color="black">^0',
     
'</font><font color="red">^1',

     ...
etc); 


If you want the ^0, ^1's removed then the array I suggested before -

PHP Code:
 $replace = array (
     
'</font><font color="black">',
     
'</font><font color="red">',

     ...
etc); 


will work fine.

Hope this helps,

-KM-

Reply With Quote
  #5  
Old October 11th, 2003, 10:25 PM
Vasarab69 Vasarab69 is offline
Goldmember
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 71 Vasarab69 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 25 sec
Reputation Power: 7
Send a message via AIM to Vasarab69
so I've got array $search:

PHP Code:
 $search        =    array (

        
'^0',
        
'^1',
        
'^2',
        
'^3',
        
'^4',
        
'^5',
        
'^6',
        
'^7',

    ); 


and I've defined the username (stripped of Carat+Number's) like so:

PHP Code:
 $new_colored_stripped    =    str_replace($search""$newcolored); 


I'm wondering why the Carat+Number's aren't being replaced by nothing... running:

PHP Code:
 $newcolored "^2john^1doe"


through this should produce:

PHP Code:
 $new_colored_stripped "johndoe"


but it isn't... any ideas?

Reply With Quote
  #6  
Old October 12th, 2003, 04:55 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 6
You've got an extra comma at the end of your array definition. After '^7' you just want the closing bracket not a comma first.

PHP Code:
 $search        =    array (

        
'^0',
        
'^1',
        
'^2',
        
'^3',
        
'^4',
        
'^5',
        
'^6',
        
'^7'

    
); 


Hope that helps,

-KM-

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Replacing carat's in account names..


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT