我的问题是,我使用特殊字符&作为重点,这似乎不工作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'
),
)
)
当我想使用namesToSubmit我得到一个错误,该属性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,didn't工作,但感谢你的帮助
使用'md5(“GmbH&Co.KG”)'值作为密钥 – DevZer0
您是否在动态获取'GmbH&Co.KG',或者您是否期望它是? – JohnnyFaldo
ideone工作得很好:http://ideone.com/oidyJF – jh314