Solved

PHP MySQL query  spaces become: T T T T T

Posted on 2014-12-31
4
131 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 62

Expert Comment

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

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

776 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