这里有数据
'7000000000000088757' : 'Orchid',
'7000000000000088737' : 'Lavender',
'7000000000000000053' : 'White',
'7000000000000000487' : 'Pink',
'7000000000000000536' : 'Yellow',
'7000000000000140533' : 'Tangerine'
我只需要
Orchid
Lavender
White
Pink
Yellow
Tangerine
如何仅通过PHP获取这些值
答案 0 :(得分:1)
你的问题有点模糊。这些是单独的字符串吗?很简单:
$array = explode(':', $value);
$word = $array[1]
如果它是一个字符串,则首先将其拆分,然后提取值
$array1 = explode(',' $string);
foreach($array1 as $value) {
$array = explode(':', $value);
$word = $array[1];
$word_no_commas = preg_replace("/ '(.+)'/i", "$1", $word);
}
如果您使用的是PHP 5.4+,则可以执行以下操作:
$arrray = explode(':', $value)[1];
答案 1 :(得分:1)
试试这个
$string = "'7000000000000088757' : 'Orchid',
'7000000000000088737' : 'Lavender',
'7000000000000000053' : 'White',
'7000000000000000487' : 'Pink',
'7000000000000000536' : 'Yellow',
'7000000000000140533' : 'Tangerine'";
$values = array();
preg_match_all("/[a-zA-Z]{1,}/", $string, $values);
然后你有
Array
(
[0] => Array
(
[0] => Orchid
[1] => Lavender
[2] => White
[3] => Pink
[4] => Yellow
[5] => Tangerine
)
)
答案 2 :(得分:1)
你可以试试这个
$initial_string =
"'7000000000000088757' : 'Orchid',
'7000000000000088737' : 'Lavender',
'7000000000000000053' : 'White',
'7000000000000000487' : 'Pink',
'7000000000000000536' : 'Yellow',
'7000000000000140533' : 'Tangerine'";
$exp1 = array(explode(",",$initial_string));
$exp2 = array();
for($x=0;$x<count($exp1[0])-1;$x++)
{
$exp2[] = explode(":",$exp1[0][$x]);
}
for($y=0;$y<count($exp2);$y++)
{
echo $exp2[$y][1]; //this is to print out the flower names
}