Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 138
  • Last Modified:

PHP MySQL query spaces become: T T T T T

I'm using Ajax to query the database and display the text on a page.   If the text in the database has spaces for example:

"text                                   text."

it becomes:

"textТ Т Т Т Т Т Т Т Т Т Т Т Т Т Т Т Т Т Т Т Т Т Т Т Т Т Т Т Т Т Т Т Т Т Т text"

If I then submit that it becomes this:

textаЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ  text

I can't find anything online that explains this behavior.  

Even if I do a string replace in Javascript I can't get rid of it.   I can change the t in text or the e or the word text.  But If I try to replace the /T /  nothing will happen.  

I think it may be some kind of Unicode character
0
vrosas_03
Asked:
vrosas_03
1 Solution
 
ozoCommented:
Can you post the code that does the query and display?
0
 
gheistCommented:
There are no unicode characters in your firt or second string.
0
 
Ray PaseurCommented:
This is a mystery that may be explained by a character-encoding mismatch.  This string appears to be valid UTF-8:
textаЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ аЂТ  text

That leads me to believe that each blank was somehow transformed into "аЂТ " which is something I have never seen before, and I've seen a lot.

The hexadecimal values of this string are: "d0 b0 d0 82 d0 a2 20"

The d0 b0 renders the letter "a"
The d0 82 renders this thing "Ђ"
The d0 a2 renders the letter "T"
And the 20 renders the trailing blank

Maybe if you can show us the original data and some of the programming we can help figure out where the transformation is occurring.  You may also want to check your character-set encoding for consistency throughout.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11880-Unicode-PHP-and-Character-Collisions.html
0
 
vrosas_03Author Commented:
I'm working with an editable div and sending the data using jQuery.ajax.   It was confusing because the problem appears to have happened in two separate ways.  First I would see the T's in firebug in the ajax post variable.  It would appear as &\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 as the response.    The spaces would appear in the phpmyadmin as just spaces with no problems.   But when I would call it from the database it would appear as T's   After getting it from the database I used the preg_replace ord command to isolate the character which turned out to be 194  which in the extended ascii character set is used to create boxes and it's shaped like a T so I guess it's to create adjoining boxes.   I used this expression to get rid of it:
$event->body = preg_replace('/\xC2/', "", $event->body)
The spaces were still there.  For some reason it's like there is a regular expression going on behind the scenes adding adding an extra character.     It seems like a character set problem.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now