PHP: special character as key in array(PHP:特殊字符作为数组中的键)
本文介绍了PHP:特殊字符作为数组中的键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题是我使用特殊字符&;作为密钥,这似乎不起作用
我的数组是这样的
$legalforms = array(
'GmbH & Co.KG' => array(
'namesToSubmit' =>array(
'companyName'=>'required',
'location'=>'required',
'phone'=>null,
'fax'=>null,
'web'=>null,
'registryCourt'=>'required',
'registryNumber'=>'required',
'companyNameAssociate'=>'required',
'locationAssociate'=>'required',
'registryCourtAssociate'=>'required',
'registryNumberAssociate'=>'requuired',
'ceo'=>'required'
),
)
)
当我想要使用名称ToSubmit时,我得到一个错误,即nameToSubmit的属性为空,如果我删除其中的特殊字符&;,它就可以工作。那么,如何使其与&;一起使用?
编辑:
$("#sendLegalForm").click(function () {
selection = $('#selection').val();
$.ajax({
type:'GET',
url:'http://192.168.10.24/php/sig.php?selectedLegalform='+ selection,
dataType:'json',
success: function (data){
$("#legalform").hide();
$("#fields").show();
var fieldnames =[];
for(property in data.namesToSubmit){
fieldnames.push(property);
}
var fields=[];
for(var i=0; i<data.textfieldHeaders.length; i++){
fields.push(data.textfieldHeaders[i],'<br>','<input name="',fieldnames[i],'" type="text" ',data.namesToSubmit[fieldnames[i]] == "required"?"required":"",'>','<br/>');
}
fields.push("<br>", 'Pflichtfelder (*)');
$("#fieldsForm").prepend(fields.join(''));
},
error: function(jqXHR,textStatus,errorThrown){
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
}
});
});
我在该行中看到错误
for(property in data.namesToSubmit){
尝试了MD5,不起作用,但谢谢您的帮助
推荐答案
将请求方法改为POST
:
$.ajax({
type:'POST',
url: 'http://192.168.10.24/php/sig.php',
data: {selectedLegalform: selection},
...
在PHP中:
$data = $_POST['selectedLegalform'];
如果通过GET
发送字符串GmbH & Co.KG
,它将变为GmbH%20%26%20Co%2EKG
。这应该是问题所在。
这篇关于PHP:特殊字符作为数组中的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:PHP:特殊字符作为数组中的键


猜你喜欢
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01