eevan79 Posted February 12, 2010 Share Posted February 12, 2010 I am not sure is this question is in right section, but I have problem with some strange characters. Can I somehow remove this character via .php script? This is screenshots: This is how it looks in Mysql: Php script: <?php $sql = "SELECT winner, a.gameid, b.colour, newcolour, original as hero, description, kills, deaths, assists, creepkills, creepdenies, neutralkills, towerkills, gold, item1, item2, item3, item4, item5, item6, it1.icon as itemicon1, it2.icon as itemicon2, it3.icon as itemicon3, it4.icon as itemicon4, it5.icon as itemicon5, it6.icon as itemicon6, it1.name as itemname1, it2.name as itemname2, it3.name as itemname3, it4.name as itemname4, it5.name as itemname5, it6.name as itemname6, leftreason, b.left, b.name as name, e.name as banname FROM dotaplayers AS a LEFT JOIN gameplayers AS b ON b.gameid = a.gameid and a.colour = b.colour LEFT JOIN dotagames AS c ON c.gameid = a.gameid LEFT JOIN games AS d ON d.id = a.gameid LEFT JOIN bans as e ON b.name = e.name LEFT JOIN heroes as f ON hero = heroid LEFT JOIN items as it1 ON it1.itemid = item1 LEFT JOIN items as it2 ON it2.itemid = item2 LEFT JOIN items as it3 ON it3.itemid = item3 LEFT JOIN items as it4 ON it4.itemid = item4 LEFT JOIN items as it5 ON it5.itemid = item5 LEFT JOIN items as it6 ON it6.itemid = item6 where a.gameid='$gid' order by newcolour"; ...than foreach ($dbHandle->query($sql, PDO::FETCH_ASSOC) as $row) { ... [code=php:0]$name=$row["name"]; and script to print: <a <?php if($banname<>'') { print 'style="color:#e56879"'; } ?> href="?p=user&u=<?php print $name; ?>&s=datetime&o=desc&n=<?php if($displayStyle=='all'){ print 'all'; } else { print '0'; } ?>" target="_self"><b><?php print $name; ?></b></a> Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted February 12, 2010 Share Posted February 12, 2010 change the encoding of your site to ISO-8859-1. That should clear it up <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> Quote Link to comment Share on other sites More sharing options...
eevan79 Posted February 12, 2010 Author Share Posted February 12, 2010 Thanks for reply. Ok, I have change it but still can see this bugged characters. I say bugged cause that characters no one write in his name. (this strange characters sometimes appear, but not offen). Also, when I change charset this I got on main page: itemi se raÄunaju sada insted of: itemi se računaju sada. I just wont to remove those characters if its possible (maybe script to search sql table, find and update)? Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted February 12, 2010 Share Posted February 12, 2010 Use either a str_replace or preg_replace on it to remove the characters you don't want to see. Quote Link to comment Share on other sites More sharing options...
eevan79 Posted February 12, 2010 Author Share Posted February 12, 2010 Ok, I tried: $name=$row["name"]; $replaceme = $name; $name=str_replace("€", " ", $replaceme); And its working. Only is problem cause there is no statistic data for player who have this character (stored in mysql - with €). But nothing is perfect. Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted February 12, 2010 Share Posted February 12, 2010 change that back to what it was. in your output part of your script above change the final <?php print $name; ?> to <?php print str_replace('€'. '', $name); ?> Quote Link to comment Share on other sites More sharing options...
eevan79 Posted February 12, 2010 Author Share Posted February 12, 2010 Yea, silly me ...unnecessary string. Too bad, its only replace output, but not table in sql. Probably I need to change some code in program that update data in mysql (written in C++). Ok...thanks JAY6390, this part is solved. Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted February 12, 2010 Share Posted February 12, 2010 You could use the REPLACE command in mysql and run it on each of the usernames http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace Example UPDATE `user_table_name` SET `username_column` = REPLACE(`username_column`, '€', '') That will replace all usernames so that they have no € in the names (change the table and column names to the ones in your table, then run the query either with a simple script or phpmyadmin Quote Link to comment Share on other sites More sharing options...
eevan79 Posted February 12, 2010 Author Share Posted February 12, 2010 Ok. Is it smart to run this script via .php? For example: $sql = "UPDATE 'gameplayers' SET 'name' = REPLACE('name', '€', '')'"; gameplayers is table, name is column. Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted February 12, 2010 Share Posted February 12, 2010 It would actually be $sql = "UPDATE `gameplayers` SET `name` = REPLACE(`name`, '€', '')"; Note that I used backticks ` around the table and column names - This is because they're identifiers not string values. You also had an extra ' at the end of your query As for running this in php it's perfectly fine Quote Link to comment Share on other sites More sharing options...
eevan79 Posted February 12, 2010 Author Share Posted February 12, 2010 Right. It's working. I appreciate your help. Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted February 12, 2010 Share Posted February 12, 2010 No problem Quote Link to comment Share on other sites More sharing options...
eevan79 Posted February 12, 2010 Author Share Posted February 12, 2010 Unfortunately, solving this problem cause another There is some empty space. Here is picture: I have selected only blank space (so its blue). And on page: I have tried this code: $sql = "UPDATE `gameplayers` SET `name` = REPLACE(`name`, ' ', '')"; $result = mysql_query($sql); But nothing happend. And then tried some combinations, but than all spaces in names was removed (ex. my nick -> mynick). Just need to remove few empty spaces after nick (not in middle). Ok, I found here: http://dev.mysql.com/doc/refman/5.1/en/string-functions.html Probably need to use "LTRIM - Remove leading spaces", but not sure about it (and dont screw other nicknames). EDIT2: I think I found it: http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_rtrim Quote Link to comment Share on other sites More sharing options...
eevan79 Posted February 12, 2010 Author Share Posted February 12, 2010 I can't edit... This code is not working: $sql = "UPDATE `gameplayers` SET `name` = RTRIM(`name`)"; I dont know how to remove empty spaces after name. Quote Link to comment Share on other sites More sharing options...
sader Posted February 12, 2010 Share Posted February 12, 2010 didi u try execute this query with phpmyadmin? Query looks absolutly fine but who knows maybe u not connected to database or something Quote Link to comment Share on other sites More sharing options...
eevan79 Posted February 12, 2010 Author Share Posted February 12, 2010 I have tried. 0 row(s) affected. ( Query took 0.0030 sec ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.