1

I have a string that's coming from an MSSQL PHP query that's interpreting spaces in some varchar rows as +. So a company name like My Company - Springfield, Illinois is delivered to me as My+Company+-+Springfield,+Illinois. What encoding is this? Are there other characters that might be getting encoded in this way, or will a simple

var a = "My+Company+-+Springfield,+Illinois"
var newstr = a.replace(/\+/g," "); //My Company - Springfield, Illinois

suffice? But that will fail on company's with + in the name. What encoding is this and how can I work with it?

Mark Reed
  • 91,912
  • 16
  • 138
  • 175
1252748
  • 14,597
  • 32
  • 109
  • 229
  • In your example, why are some spaces replaced with + and others are not? – Geuis Feb 19 '13 at 04:47
  • I would guess that those values came from a web form that was processed by something that didn't properly decode the parameters. The character '+' is one of the options for putting spaces in query strings. (The other option is `%20`, using the general syntax which works for all characters and is used for literal plus signs, which are `%2B`). – Mark Reed Feb 19 '13 at 04:47
  • @Geuis Apologies, I wrote that out rather than copy/paste and I just missed that last one. Fixed it now. Thanks – 1252748 Feb 19 '13 at 04:48
  • What about the first one? "My Company" – Geuis Feb 19 '13 at 04:49
  • @Geuis ok. I think I've got them all now. – 1252748 Feb 19 '13 at 04:50
  • that could be the case actually as my guess http://stackoverflow.com/questions/5442658/spaces-in-urls – dmi3y Feb 19 '13 at 04:51
  • My mysql knowledge is pretty rusty. Have you checked to see if the values being returned are coming back from mysql like that, or from php? e.g. which php function(s) are you using to return/display the data? Is the character set for the column set to UTF8 or something else? – Geuis Feb 19 '13 at 04:52
  • Before anyone else decides to throw spaghetti answers at his wall, he needs to verify some of the questions I asked in the previous comment. – Geuis Feb 19 '13 at 04:57
  • after echoing the data that mssql is getting (just like `echo ".` it seems that the `+` are not there. They show as spaces. Though I find it difficult to believe php is encoding the spaces when I put them in the cookie I make from the string. I'm just using `mssql_fetch_assoc()`, putting into a cookie with php (`setcookie('user_info', json_encode($user_information), time()+60*60*24*30);`), and reading the cookie with javascript. – 1252748 Feb 19 '13 at 05:01
  • @Geuis `` – 1252748 Feb 19 '13 at 05:23
  • 1
    So the problem is not in the database it seems. Investigate how you're storing the data in the cookie. – Geuis Feb 19 '13 at 09:30

0 Answers0