views:

181

answers:

5

I have this value in a mysql database: "A+" it's the name of a magazine. I can see it sitting in the database, however i cannot manage to have it display via php. When i fetch the sql data, it outputs

"A "

I tried utfencode() utfdecode() htmlentities() ... to no avail. I fail to diagnose the problem. In case it matters, i fetch this data via ajax (jquery load() function)

UPDATE:

It turns out the + sign is removed while parsing the data through a regular expression. can't seem to find a fix for that either. preg_quote() is of no use.

+5  A: 

It is possible that jquery is interpreting it as the url encoded '+' sign, which can be interpreted as a space. Post some code and I'm sure somebody can give you a full answer.

jonstjohn
following your suggestions, i tried just outputting directly "A+" by hardcoding it in the php output string. problem remains. htmlentities did not help either. only "urlencode()" makes the + appear ! now, that's a problem: i don't want to urlencode text that should be human-readable. lost i am...
pixeline
which PHP output string? The one that produces the string in the ajax call? or directly on an otherwise empty PHP script page?
jonstjohn
a simple string, like: echo "publisher name: A+<br/>published in 1999";
pixeline
@jonstjohn: I can almost guarantee that's the problem, espcially considering pixeline's urlencode() reply.
Andrew
do you mean that my lengthy text that contains the "+" sign is sent back via a GET request? sounds weird. i thought there was a 255 character limit.
pixeline
A: 

You can add a escape character before the \ and see how that works. If not convert the field data using htmlentities

kthakore
following your suggestions, i tried just outputting directly "A+" by hardcoding it in the php output string. problem remains.htmlentities did not help either.only "urlencode()" makes the + appear ! now, that's a problem: i don't want to urlencode text that should be human-readable. lost i am...
pixeline
+1  A: 

The + character is interpreted as space when the data is declared as application/x-www-form-urlencoded:

This is the default content type. Forms submitted with this content type must be encoded as follows:

  1. Control names and values are escaped. Space characters are replaced by '+', and then reserved characters are escaped as described in [RFC1738], section 2.2: Non-alphanumeric characters are replaced by '%HH', a percent sign and two hexadecimal digits representing the ASCII code of the character. Line breaks are represented as "CR LF" pairs (i.e., '%0D%0A').
  2. The control names/values are listed in the order they appear in the document. The name is separated from the value by '=' and name/value pairs are separated from each other by '&'.

So you have to encode it properly. In JavaScript, use the encodeURIComponent function if you want to use + character in an URI:

"http://www.example.com/?q=" + encodeURIComponent("A+")
Gumbo
A: 

Do you pass it as an javascript parameter without urlencode()'ing it?

vartec
no, i don't pass it. It is sitting in the fetched html string.
pixeline
A: 

Well, since the only way to make it work is to do



echo urlencode("this is the A+ text");


It works and does not seem to damage the rest of the text, but i don't understand the rationale behind this. Anyway, thanks to all of those who tried to help.

pixeline