PHP parse_str函数用空格替换+符号

时间:2015-06-27 22:42:11

标签: php

我有一个变量我通过url作为Geometry字符串传递,其中一部分是以下字符串:

#Class Geometry
#attribute id
class Geometry(object):
    def __init__(self,uid=0):
        uid = 0
        self.uid = uid
        uid += 1 #not sure if this is neseccary. said uniqueId needs to start at 0, nothing about progressing


class Point(Geometry):
    def __init__(self,x,y):
        Geometry.def__init__(self,uid)
        self.x = x
        self.y = y

    def __str__(self):
        return self.uid + self.x + self.y

当我在php中使用jSON函数读取url并解析字符串时,signature=8W2sp\/J+kC6fh8a88jabNPuA8048sShDnXNOo1jSQ= 符号将被空格替换。有没有办法禁用空格替换parse_str()

1 个答案:

答案 0 :(得分:3)

parse_str自动将url_decode应用于给定字符串时,加号将解码为空格字符。要保持加号,您可以使用urlencode

$arr = array();
$x = "8W2sp/J+kC6fh8a88jabNPuA8048sShDnXNOo1jSQ=";
parse_str(urlencode($x),$arr);
var_dump($arr);

请参阅演示:http://codepad.org/wxLIqmIi