【发布时间】:2014-12-23 17:03:32
【问题描述】:
如何使用 php 将所有字符串包含在一对双引号中,我想将它们放在以下字符串中,
$str = 'a:2:{i:1;a:4:{i:1;s:4:"2000";i:2;s:8:"10th STD";i:3;s:9:"Full Time";i:4;s:24:"State Board of Education";}i:2;a:4:{i:1;s:4:"2003";i:2;s:8:"12th STD";i:3;s:9:"Full Time";i:4;s:24:"State Board of Education";}}';
我想要输出如下
2000
10th STD
Full Time
State Board of Education
我尝试了以下代码,但输出仅来自2000
<?php
$str = 'a:2:{i:1;a:4:{i:1;s:4:"2000";i:2;s:8:"10th STD";i:3;s:9:"Full Time";i:4;s:24:"State Board of Education";}i:2;a:4:{i:1;s:4:"2003";i:2;s:8:"12th STD";i:3;s:9:"Full Time";i:4;s:24:"State Board of Education";}}'
if (preg_match('/"([^"]+)"/', $str, $m))
{
print $m[1];
}
else
{
}
<?
请建议我怎么做,我应该使用哪个函数来获取我的输出?
【问题讨论】:
-
这看起来像一个 PHP 序列化 数组。使用
unserialize()对其进行反序列化,然后将其视为数组。甚至不要在这里使用正则表达式。