Solved

PHP MySQL query  spaces become: T T T T T

Posted on 2014-12-31
4
129 Views
Last Modified: 2015-01-04
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
Comment
Question by:vrosas_03
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 40526349
Can you post the code that does the query and display?
0
 
LVL 61

Expert Comment

by:gheist
ID: 40526400
There are no unicode characters in your firt or second string.
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 40526436
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
 

Author Closing Comment

by:vrosas_03
ID: 40530048
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now