Tibia Idle
Active Member
- Joined
- Nov 23, 2023
- Messages
- 149
- Reaction score
- 28
REGEXP_REPLACE(name, '\\s+', ' ', 1, 0)
but if there are some names that'd lead to UNIQUE constraint violation you'd need to handle that too. For example like that (It's ugly but should work):WITH normalizedMap AS (
SELECT
REGEXP_REPLACE(name, '\\s+', ' ', 1, 0) AS normalized_name,
COUNT(*) OVER (PARTITION BY REGEXP_REPLACE(name, '\\s+', ' ', 1, 0)) AS cnt,
id AS player_id
FROM players
)
UPDATE players p
INNER JOIN normalizedMap n ON n.player_id = p.id
SET p.name = n.normalized_name
WHERE n.cnt = 1;
on the page it automatically removes spaces. however, I want to fix a bug in the gamePHP:function sanitzePlayerName($name) { return preg_replace('/\s+/', ' ', trim($name)); } $name = "Jon Jons"; $sanitizedName = sanitzePlayerName($name); // "Jon Jons"
Go into your database probably using phpMyAdmin and find table players, find the player you wanna change and change their name.
In which page file should I add it? I can't find the account php filePHP:function sanitzePlayerName($name) { return preg_replace('/\s+/', ' ', trim($name)); } $name = "Jon Jons"; $sanitizedName = sanitzePlayerName($name); // "Jon Jons"
REGEXP_REPLACE(name, '\\s+', ' ', 1, 0)
but if there are some names that'd lead to UNIQUE constraint violation you'd need to handle that too. For example like that (It's ugly but should work):WITH normalizedMap AS (
SELECT
REGEXP_REPLACE(name, '\\s+', ' ', 1, 0) AS normalized_name,
COUNT(*) OVER (PARTITION BY REGEXP_REPLACE(name, '\\s+', ' ', 1, 0)) AS cnt,
id AS player_id
FROM players
)
UPDATE players p
INNER JOIN normalizedMap n ON n.player_id = p.id
SET p.name = n.normalized_name
WHERE n.cnt = 1;
thanks for help@Tubeshop Speaking of exiting entries in DB you could sanitize that with use ofREGEXP_REPLACE(name, '\\s+', ' ', 1, 0)
but if there are some names that'd lead to UNIQUE constraint violation you'd need to handle that too. For example like that (It's ugly but should work):
SQL:WITH normalizedMap AS ( SELECT REGEXP_REPLACE(name, '\\s+', ' ', 1, 0) AS normalized_name, COUNT(*) OVER (PARTITION BY REGEXP_REPLACE(name, '\\s+', ' ', 1, 0)) AS cnt, id AS player_id FROM players ) UPDATE players p INNER JOIN normalizedMap n ON n.player_id = p.id SET p.name = n.normalized_name WHERE n.cnt = 1;
Speaking of the previous code snippet it's just a proposal code you could use while saving players to DB (find a save player method in your AAC or some method that validates/sanitizes player name and put the code there)
UPDATE:
From what I see MyAAC already has some validators for that purpouse:
![]()
myaac/system/libs/validator.php at a88103a95622bcf20db64a0b25d9592f2dca21bf · slawkens/myaac
Automatic Account Creator (AAC) for Open Tibia Servers written in PHP - slawkens/myaacgithub.com