-4

Here I have data

            '7000000000000088757' : 'Orchid',
            '7000000000000088737' : 'Lavender',
            '7000000000000000053' : 'White',
            '7000000000000000487' : 'Pink',
            '7000000000000000536' : 'Yellow',
            '7000000000000140533' : 'Tangerine'

I need only

            Orchid
            Lavender
            White
            Pink
            Yellow
            Tangerine

How can I get these values only via PHP

DJ MHA
  • 598
  • 3
  • 18

3 Answers3

1

Your question is a bit vague. Are these seperate string? Very simple:

$array = explode(':', $value);
$word = $array[1]

If it is one string then firstly split it and then extract the values

$array1 = explode(',' $string);
foreach($array1 as $value) {
     $array = explode(':', $value);
     $word = $array[1];
     $word_no_commas = preg_replace("/ '(.+)'/i", "$1", $word);
}

If you are using PHP 5.4+ you can do:

$arrray = explode(':', $value)[1];
Dawid O
  • 6,091
  • 7
  • 28
  • 36
1

try this

$string = "'7000000000000088757' : 'Orchid',
            '7000000000000088737' : 'Lavender',
            '7000000000000000053' : 'White',
            '7000000000000000487' : 'Pink',
            '7000000000000000536' : 'Yellow',
            '7000000000000140533' : 'Tangerine'";

$values = array();

preg_match_all("/[a-zA-Z]{1,}/", $string, $values);

then you have

Array
(
    [0] => Array
        (
            [0] => Orchid
            [1] => Lavender
            [2] => White
            [3] => Pink
            [4] => Yellow
            [5] => Tangerine
        )

)
Thiago França
  • 1,817
  • 1
  • 15
  • 20
1

You can try this

        $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
        }
rfpdl
  • 956
  • 1
  • 11
  • 35