将Perl关联数组转换为PHP数组 [英] Convert perl associative array to PHP array

查看:71
本文介绍了将Perl关联数组转换为PHP数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有可用于将perl中的关联数组转换为php中的关联数组的php库?如果没有,是否有建议的方法?常用表达 ?一堆爆炸和内爆的电话?

Is there a php library I can use to convert an associative array in perl to an associative array in php ? If not, is there any recommended way of doing this ? Regular expressions ? A bunch of explode and implode calls ?

我想离开

my %arrayname = (
    key1 => "Value1",
    key2 => "Value2",
    key3 => "Value3",
...

$arrayname = array(
        "key1" => "Value1",
        "key2" => "Value2",
        "key3" => "Value3",


推荐答案

如果服务器上有Perl,则使用:

If you have Perl on your server, you use:

print 'Array(';
while (($key, $val) = each(%arrayname)) {
    print "'$key' => '$val',";
}
print ');';

您还可以查看 PECL Perl软件包,库在PHP中集成了Perl解析器。

You can also have a look at the PECL Perl package, this library integrates a Perl parser in PHP.

您可以使用在线Perl解释器,其中包含示例代码并可以正常工作(在该处只有一个多余的逗号

You can use an online Perl interpreter with example code and working (there is just one extra comma at the end).

我创建了一个几乎可以使用的正则表达式。您可以尝试一下,但这取决于Perl数组的结构:

I created a regex that almost works. You can try it, but it depends on the structure of the Perl array:

preg_match_all(#\%(.+)\s=|\n(.+).*#);

示例数据:

my %arrayname = (
    key1 => "Value1",
    key2 => "Value2",
    key3 => "Value3"
)

您可以使用正则表达式测试工具

这篇关于将Perl关联数组转换为PHP数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆