Get PHP Array Value

Asked

Viewed 3,226 times

2

Array
(
    [0] => 
    [1] => Array
        (
            [0] => #EXTM3U
        )
    [2] => Array
        (
            [0] => #EXTINF:-1 tvg-id="" tvg-name="BBB 18 -Aquecimento" tvg-logo"https://s9.postimg.org/4c14egx5b/big_welcome_Pic_4-300x169.png" group-title="Canais Globo",BBB 18 -Aquecimento (...)
        )

    [3] => Array
        (
            [0] => http://infinity.quor8.com:8000/live/N708Kwo02j/qsTfBzzoPk/12664.ts
        )

    [4] => Array
        (
            [0] => #EXTINF:-1 tvg-id="" tvg-name="Globo RJ FHD" tvg-logo="http://i.imgur.com/NSHvLCe.png" group-title="Canais Globo",Globo RJ FHD
        )
)

I have this array above and need to take only the value of tvg-logo

I tried that way here: $array[2][tvg-logo];

But that was the result:

#EXTINF:-1 tvg-id="" tvg-name="BBB 18 -Aquecimento" tvg-logo="https://s9.postimg.org/4c14egx5b/big_Welcome_Pic_4-300x169.png" group-title="Canais Globo",BBB 18 -Aquecimento

as I said I need only the value of tvg-logo

Anyone can help ?

2 answers

0

You can use the function of parser and save each part of the array’s string into a variable, using the function:

void parse_str ( string $encoded_string [, array &$result ] )

in your case: Accessing the value of $array[0][2]

You have: "EXTINF:-1 tvg-id="" tvg-name="BBB 18 -Heating" tvg-logo="https://s9.postimg.org/4c14egx5b/big_Welcome_Pic_4-300x169.png" group-title="Canais Globo",BBB 18 -Heating";

With that you can:

parse_str($suaString, $resultado);

...
echo $resultado['tvg-id']; // ""
echo $resultado['tvg-name']; // "BBB 18 -Aquecimento
echo $resultado['tvg-logo']; // https://s9.postimg.org/4c14egx5b/big_Welcome_Pic_4-300x169.png
...
  • Hello Bsants, thanks for the help, I have not much experience with this, you could tell me how to do it in php, I tried to play what you said but I did not succeed

  • Hello, just put the code inside the php tag <?php ?>, if necessary, have a look at the documentation: http://php.net/manualen/function.parse-str.php. Otherwise, just manipulate the result of your $array. You can save the result to a new $suaString variable = $array[0][2] as in the example.

  • Look how I did: $string = $array; echo "</pre>"; parse_str($string, $result); echo $result['tvg-id']; // "" echo $result['tvg-name']; /// "BBB 18 -Heating echo $result['tvg-logo']; // he returns: Warning: parse_str() expects Parameter 1 to be string, array Given in /home/u805601857/public_html/canais1.php on line 43

  • You can use a var_dump() http://php.net/manual/en/function.var-dump.php in the variable to see if it really is receiving what is expected, but it is error in the line 43. Test the same thing just with:tvg-id="" tvg-name="BBB 18 -Aquecimento" tvg-logo="https://s9.postimg.org/4c14egx5b/big_Welcome_Pic_4-300x169.png"

  • Look how I did it this time: code&#xA; $string_antiga = $array[2][0];&#xA;&#xA;parse_str($string_antiga , $resultado);&#xA;&#xA;echo $resultado['tvg-id'];&#xA;echo $resultado['tvg-name'];&#xA;echo $resultado['tvg-logo'];&#xA;&#xA;&#xA; But it returns no result.

  • Would not be $array[0][2] ?? Another way would be to use the function explode() http://php.net/manual/en/function.explode.php marking after the signal from =. $string_antiga = "tvg-id="" tvg-name="BBB 18 -Aquecimento" tvg-logo="https://s9.postimg.org/4c14egx5b/big_Welcome_Pic_4‌​-300x169.png"; $string_nova = explode("=", $string_antiga); echo $string_nova[0]; echo $string_nova[1]; echo $string_nova[2];

  • returned me the value: code #EXTINF:-1 tvg-id"" tvg-name"BBB 18 -Aquecimento" tvg-logo I need to return only the value of tvg-logo

  • That’s what the $string_nova will receive already indexing the fields. Now you need to access the corresponding position you need. For example, give a echo in $string_nova[2]. Check the examples that are in the links of the documentation I sent you.

  • doing so he retouche me this code "https://s9.postimg.org/4c14egx5b/big_Welcome_Pic_4-300x169.png" group-title see that you brought group-title to remove and leave only url ? so I only left echo $string_nova[3]; to receive this above.

  • I get it. I can’t solve this problem. You could take advantage of this new problem and create another question that will definitely help you, or edit in your own post.

  • Thanks Amigo!

Show 6 more comments

0

The final resolution for what I wanted was like this:

$string_antiga = $array[10][0]; 

preg_match_all("/\"[^\"]*\"/",$string_antiga,$x);
echo '<pre>'; print_r($x);

echo $x[0][2];

thanks to everyone who tried to help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.