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:特殊字符作为数组中的键


基础教程推荐
猜你喜欢
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 在多维数组中查找最大值 2021-01-01