PHP view slash problem
Sun, 01/20/2013 - 23:55
Hi
When I have a problem when I use php view function
Here is the problem, if I want to select something like startkey=['apple', null]&endkey=['apple', "\u0fff"]
I can easily type this in couchbase web filter and sure it gives me what I want (I want select all results).
But, if I write this in php code
$cb->view("task", "apple", array('startkey'=>['apple', null], 'endkey'=>['apple', '\u0fff']));
It returned nothing!!
then I tried this
echo urldecode($cb->viewGenQuery("task", "task_apple", array('startkey'=>['apple', null], 'endkey'=>['apple', '\u0fff'])));
result:
/_design/task/_view/task_apple?startkey=["apple",null]&endkey=["apple","\\u0fff"]
turns out it adds an extra slash there, how do I solve this problem? thanks....
Since the input array itself becomes serialized to JSON, as a consequence any character which is "special" to JSON is escaped as well. I am guessing the only way you can get the effect of \u0fff is to place a literal one inside the string. Hopefully PHP's json encoding will do the trick.
You can also disable smart serialization of parameters (via OPT_PASSTHROUGH) - which means that instead of passing an array to 'startkey' it would need to be an already-serialized JSON array