沃梦达 / 编程问答 / php问题 / 正文

PHP:特殊字符作为数组中的键

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

基础教程推荐