如何通过使用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";}}';
Run Code Online (Sandbox Code Playgroud)
我想要输出如下
2000
10th STD
Full Time
State Board of Education
Run Code Online (Sandbox Code Playgroud)
我尝试了以下代码,但仅输出 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
{
}
<?
Run Code Online (Sandbox Code Playgroud)
请建议我怎么做,我应该用哪个功能来获取输出?
希望这会对你有所帮助.
<?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";}}';
$str_array = unserialize($str);
foreach($str_array as $values) {
foreach($values as $value) {
echo $value . '<br/>';
}
echo '<br/>';
}
?>
Run Code Online (Sandbox Code Playgroud)
将返回:
2000年
第10届STD
全职
教育委员会
2003年
第12届STD
全职
教育委员会