socket_read => Array

Gestart doorWouterr4 reacties55 weergaven

5 berichten · pagina 1 van 1

Wouterr

Lid · Topicstarter

Berichten
5.274
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien

Eindhoven, Nederland

Hey.

Ik heb een probleem, ik weet gewoon even niet meer hoe dit zit:

Ik heb nu dit:

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/print_r"]print_r[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/socket_read"]socket_read[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sock[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]1024[/COLOR][COLOR= #007700]));[/COLOR]
?>


Dan komt er dit te staan:

Quote:
B{"packets":[{"command":"playerStatus","responseCommand":"false"}]}

Alleen hoe kan ik dus nou de variable van responseCommand pakken?
Daar hoef ik tog niet met explode enz te gaan klooien? Dat was tog iets met:

[COLOR= #0000BB]<?php
$array[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/socket_read"]socket_read[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sock[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]1024[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"packets"[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]"responseCommand"[/COLOR][COLOR= #007700]];[/COLOR]
?>


alleen dan komt de volgende error:

Quote:
Fatal error: Cannot use string offset as an array in /home/snabbonl/domains/nlminecraft.nl/public_html/allesgoed.php on line 23

line 23 is de echo.

Hoe kan ik dit oplossen?

Bedankt!
Wouter.
0
Berichten
35.796
Reputatie
1
Punten
0,00
Lid sinds
Laatst gezien
Hij geeft een string terug, geen array.

Je kunt hem o.a. zo pakken denk:
$response = explode(responseCommand":", $string);
$response = explode(", $response[1]);
$response = $response[0];

Er zal alleen wel een goede functie voor zijn, maar die weet ik zo niet. biggrin
0
Wouterr

Lid · Topicstarter

Berichten
5.274
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien

Eindhoven, Nederland

Oh, Okay..
Kan het ook JSON zijn?
Alleen als ik dan dit doe:

$array = json_decode(socket_read($sock, 1024));
    echo $array[packets][responseCommand];


komt er niks te staan. (Volgens mij zat het met JSON, zo verzend ik ook de data naar de server namelijk)
0
Berichten
35.796
Reputatie
1
Punten
0,00
Lid sinds
Laatst gezien
Doe dan eens print_r over die $array
0
Wouterr

Lid · Topicstarter

Berichten
5.274
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien

Eindhoven, Nederland

[COLOR= #0000BB]<?php[/COLOR]
    try[COLOR= #007700]{[/COLOR]
        [COLOR= #0000BB]$array[/COLOR] [COLOR= #007700]=[/COLOR] json_decode[COLOR= #007700]([/COLOR][URL="http://www.php.net/socket_read"]socket_read[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sock[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]1024[/COLOR][COLOR= #007700]));[/COLOR]
        [URL="http://www.php.net/print_r"]print_r[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$array[/COLOR][COLOR= #007700]);
    }[/COLOR]catch[COLOR= #007700]([/COLOR]Exception [COLOR= #0000BB]$e[/COLOR][COLOR= #007700]){[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Fail[/COLOR][COLOR= #007700];
    }[/COLOR]
?>


Hij geeft wit weer. Geen text..

Naja, opgelost met jouw explode stukje, ty hypocrite
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren