在Perl CGI中处理HTML表单中的PHP样式数组(方括号)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Perl CGI中处理HTML表单中的PHP样式数组(方括号)相关的知识,希望对你有一定的参考价值。
This is inspired by this http://www.cgi101.com/book/ch5/text.html so I'm using a similar example. In php you can combine a set of checkboxes into an array using square brackets like this:Red
Green
Blue
Gold
PHP does not do this automatically but it's pretty simple to do if you filter by regular expressions.
use CGI; $query = CGI::new(); my %fields_temp = $query->Vars; my %fields = (); if ( $key =~ /(.+)[]$/ ) { ## Handle PHP style array inputs $fields{$1} = $fields{$1} . ",". $fields_temp{$key}; } else{ $fields{$1} = $fields_temp{$key}; } } else { $fields{$key} = $fields_temp{$key}; } } unless ($key =~ /(.+)[]$/ ){ } }
以上是关于在Perl CGI中处理HTML表单中的PHP样式数组(方括号)的主要内容,如果未能解决你的问题,请参考以下文章