I am trying to pass an argument containing apostrophe character to function call but apparently it is being stripped out. Here's what I am doing:
$input = array(
'kod_modelu' => "187'",
'nr_nadwozia' => '00552889'
);
$result = $client->call('certyfikat_gwarancji_dane_pobierz', $input);
var_dump($result);
And in output I'm getting:
'kod_modelu' => string '187' (length=3)
'nr_nadwozia' => string '00552889' (length=8)
(I am repeating input in output and apostrophe is being stripped out).
How can I solve this?
EDIT: Here's a code to reproduce the issue:
Pastebin
Ok, case closed.
PHP 5.2.6 is the issue (referring to bugs.php.net). Upgrading to the latest version of 5.2.x branch solves the problem.
This might be a long shot, but since SOAP is XML based your quotes must be converted to XML entities somewhere.
I have no experience with nuSOAP, but a single quote's XML entity value is: '.
Refer to the PHP function: htmlspecialchars()
Related
$requestParams = [ 'aame_uuid' => 'aba627', 'currency' => 'TEST'];
ksort($requestParams);
$hashString = http_build_query($requestParams);
var_dump( $hashString);
gives
string(30) "aame_uuid=aba627¤cy=TEST"
so why does currency transformed to ¤cy , how can correct it ?
I think the problem is the ¤ html code.
http://character-code.com/currency-html-codes.php ¤ gets replaced to this char.
Maybe you should add an specific seperator like &
to the http_build_query to make sure it will replaced to foo.php?aaaa_uid=aba627¤cy=Test
I just tested your code and I get the following string back:
C:\wamp64\www\test\test.php:8:string 'aame_uuid=aba627¤cy=TEST' (length=30)
It seems to be working fine for me. Have you tried using some other key? If it gives somewhat the same result your file or server could be corrupt.
If not the word curren might be presaved as a function to do something (which is highly unlikely). Did you mistype it as currentcy maybe (current is a php function)?
I've got a simple mongo query which returns the result I want -
db.properties.findOne({$text:{$search:'\"Eiffel Petit Louvre\"'}})
However I can't seem to transpose the same query into php -
$searchString = '\"Eiffel Petit Louvre\"';
$hotel = $db->properties->findOne(
array('$text' => array('$search' => $searchString))
);
This doesn't give me any results back. What am I doing wrong? I'm guessing it's the string. I've tried escaping the backslashes (I don't think I should need to since the string uses single quotes), but that didn't work.
Hi I had the exact same problem. After long trial and error I figured out that the following works:
array('$text'=>array('$search'=>"\"$searchString\""))
Well, I'm trying to retrieve some info, from the Google Suggest tool.
The thing is, the json returned after the request, doesn't seem decode-able (using json_decode) + JSONLint sees it as "invalid".
What's wrong?
{
e: "GooDUs7lFIeXO63LgBA",
c: 0,
u: "https://www.google.com/s?gs_rn\x3d24\x26gs_ri\x3dpsy-ab\x26tok\x3dt8ORbtI13MEFLoCQjPSv6w\x26cp\x3d2\x26gs_id\x3d3i\x26xhr\x3dt\x26q\x3dtemplate\x26es_nrs\x3dtrue\x26pf\x3dp\x26safe\x3doff\x26sclient\x3dpsy-ab\x26oq\x3d\x26gs_l\x3d\x26pbx\x3d1\x26bav\x3don.2,or.r_cp.r_qf.\x26bvm\x3dbv.50500085,d.bGE\x26fp\x3dc513cf9c63a02102\x26biw\x3d1304\x26bih\x3d437\x26tch\x3d1\x26ech\x3d20\x26psi\x3dFYkDUs-xCsrT4QTD9YGwDw.1375963413783.1",
p: true,
d: "[\x22template\x22,[[\x22template\\u003cb\\u003es\\u003c\\/b\\u003e\x22,0],[\x22template\\u003cb\\u003e monster\\u003c\\/b\\u003e\x22,0],[\x22template\\u003cb\\u003e c++\\u003c\\/b\\u003e\x22,0],[\x22template\\u003cb\\u003es for pages\\u003c\\/b\\u003e\x22,0]],{\x22t\x22:{\x22bpc\x22:false,\x22tlw\x22:false},\x22q\x22:\x22YjrI_EdhVrEkZrkqZwaGIJ_Ih4c\x22,\x22j\x22:\x223i\x22}]"
}
That's what JSONLint gives as an error :
Parse error on line 1:
{ e: "GooDUs7lFIeXO63L
-----^
Expecting 'STRING', '}'
P.S. Even after editing it like "e": and so on, it still gives out error regarding the value of u and claiming that it was expecting a STRING or NUMBER etc... :S
The code given in the question is not valid JSON.
In order to be valid JSON, it would be required to have the field named in quotes. There are no quotes around the e variable name, or any of the others.
This is what the JSON decoder is complaining about: It is expecting to see "e", not e.
In addition, JSON does not accept the \x escaping format (character reference in hex); it can only use the \u format (unicode character reference in decimal). The code you've provided includes escaped characters in both formats.
The question is, are you using an official Google API? Because they're usually pretty good at providing valid JSON. This isn't valid JSON, so it may be that you're not using the correct API. Another clue is that the variable names aren't very meaningful; offical APIs would normally give more meaningful variable names. If it is the correct API, you should try raising a ticket with Google to fix it; broken JSON is not good, but it should be pretty trivial for them to fix.
Assuming you can't get them to fix it and we can't find an alternative API location that does give valid data, how do we deal with what we've got?
While this code may not be valid JSON, it is valid as a Javascript object (the JSON rules are stricter that those of plain Javascript). It could therefore be run in a Javascript interpreter using eval(), if you trusted it enough for that.
The only other alternativate is to fix the string prior to parsing it so that the variable names are quoted. That's a bit of a pain, but would be do-able if the output was consistent. You'll have problems though if it ever changes (and again, if it's an unofficial API, that could happen at any time without warning).
The problem is with the backslashes in the strings (used for the escape characters)
In PHP 5.4, you can use JSON_UNESCAPED_SLASHES:
echo json_encode(JSON_STRING, JSON_UNESCAPED_SLASHES);
Otherwise, you can do the replacement-
str_replace('\\/', '/', json_encode(JSON_STRING));
Since \/ is a valid way to represent /
OK, so this is what I ended up doing (not elegant at all but it works) :
$content = preg_replace_callback(
"(\\\\x([0-9a-f]{2}))i",
function($a) {return chr(hexdec($a[1]));},
$content
);
$content = str_replace("e:","\"e\":",$content);
$content = str_replace("c:","\"c\":",$content);
$content = str_replace("u:","\"u\":",$content);
$content = str_replace("p:","\"p\":",$content);
$content = str_replace("d:","\"d\":",$content);
$content = str_replace("\"[","[",$content);
$content = str_replace("]\"","]",$content);
$content = json_decode($content);
I'm writing PHP code that uses a database. To do so, I use an array as a hash-map.
Every time content is added or removed from my DB, I save it to file.
I'm forced by my DB structure to use this method and can't use mysql or any other standard DB (School project, so structure stays as is).
I built two functions:
function saveDB($db){
$json_db = json_encode($db);
file_put_contents("wordsDB.json", $json_db);
} // saveDB
function loadDB(){
$json_db = file_get_contents("wordsDB.json");
return json_decode($json_db, true);
} // loadDB
When echo-ing the string I get after the encoding or after loading from file, I get a valid json (Tested it on a json viewer) Whenever I try to decode the string using json_decode(), I get null (Tested it with var_dump()).
The json string itself is very long (~200,000 characters, and that's just for testing).
I tried the following:
Replacing single/double-quotes with double/single-quotes (Without any backslashes, with one backslash and three backslashes. And any combination I could think of with a different number of backslashes in the original and replaced string), both manually and using str_replace().
Adding quotes before and after the json string.
Changing the page's encoding.
Decoding without saving to file (Right after encoding).
Checked for slashes and backslashes. None to be found.
Tried addslashes().
Tried using various "Escape String" variants.
json_last_error() doesn't work. I get no error number (Get null, not 0).
It's not my server, so I'm not sure what PHP version is used, and I can't upgrade/downgrade/install anything.
I believe the size has something to do with it, because small strings seem to work fine.
Thanks Everybody :)
In your JSON file change null to "null" and it will solve the problem.
Check if your file is UTF8 encoded. json_decode works with UTF8 encoded data only.
EDIT:
After I saw uploaded JSON data, I did some digging and found that there are 'null' key. Search for:
"exceeding":{"S01E01.html":{"2217":1}},null:{"S01E01.html":
Change that null to be valid property name and json_decode will do the job.
I had a similar problem last week. my json was valid according to jsonlint.com.
My json string contained a # and a & and those two made json_decode fail and return null.
by using var_dump(json_decode($myvar)) which stops right where it fails I managed to figure out where the problem was coming from.
I suggest var_dumping and using find dunction to look for these king of characters.
Just on the off chance.. and more for anyone hitting this thread rather than the OP's issue...I missed the following, someone had htmlentities($json) way above me in the call stack. Just ensure you haven't been bitten by the same and check the html source.
Kickself #124
Sorry I can’t log in claim ID is having server issues (im normally Arthur Gibbs)
Data from my database currently outputs this when there are strange charecters...
This is just a example
What I get: De√ilscrat™
What I want: De√ilscrat™
It seems that some characters are being translated into character code by the other guys system..
So what I want to know is:
Is there a function that will expand charecter codes within a string?
Turning FUNCTION(De√ilscrat™) >>> De√ilscrat™.
This √ stuff looks like an HTML entity ; so, let's try de-entitying it...
This can be done using the html_entity_decode function, that's provided by PHP.
For instance, with the string you provided, here's a sample of code :
// So the browser interprets the correct charsert
header('Content-type: text/html; charset=UTF-8');
$input = 'De√ilscrat™';
$output = html_entity_decode($input, ENT_NOQUOTES, 'UTF-8');
var_dump($input, $output);
And the output I'm getting is this one :
string 'De√ilscrat™' (length=19)
string 'De√ilscrat™' (length=15)
(First one is the original version, and second one is the "decoded" version)
So, it seems to do the trick ;-)