|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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:
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 |
|
#2
|
|||
|
|||
|
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:
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:
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- |
|
#3
|
|||
|
|||
|
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 . |
|
#4
|
|||
|
|||
|
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:
If you want the ^0, ^1's removed then the array I suggested before - PHP Code:
will work fine. Hope this helps, -KM- |
|
#5
|
|||
|
|||
|
so I've got array $search:
PHP Code:
and I've defined the username (stripped of Carat+Number's) like so: PHP Code:
I'm wondering why the Carat+Number's aren't being replaced by nothing... running: PHP Code:
through this should produce: PHP Code:
but it isn't... any ideas? |
|
#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:
Hope that helps, -KM- |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Replacing carat's in account names.. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|