在PHP中解码变量

时间:2016-03-21 12:22:16

标签: php magento server

我写了这个函数来创建magento的新帐户,但是如果我写阿拉伯语单词,它会发送编码数据,并且数据是用url编码的,所以我想解码它。并使用像

这样的编码数据创建帐户
%D9%85%D8%AD%D9%85%D8%AF %D8%B5%D8%A7%D8%A8%D8%B1

原始字[ محمد صابر ]

function register($email , $password , $firstname , $lastname  )
{
$customer = Mage::getModel('customer/customer');
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
$customer->loadByEmail($email);
if(!$customer->getId()) {
    $customer->setEmail(utf8_decode($email));
    $customer->setFirstname(utf8_decode($firstname));
    $customer->setLastname(utf8_decode($lastname));
    $customer->setPassword(utf8_decode($password));

    try {
    $customer->save();
    $customer->setConfirmation(null);
    $response["success"] = 1;

}
catch (Exception $ex) {
    $response["success"] = 0;
}

}
else{
$response["success"] = 0;
}
header('Content-Type: application/json; charset=utf-8');
return json_encode($response);
}

1 个答案:

答案 0 :(得分:1)

使用urldecode()

$decodedString = urldecode($endodedString);