WIK Posted March 1, 2021 Report Posted March 1, 2021 bun, ideea e ca am un tabel in baza de date care-mi stocheaza informatiile asa: {"fLeader":1,"customization":{"1":[0,0,0],"2":[0,0,0],"3":[0,0,1],"4":[0,0,1],"5":[0,0,0],"6":[0,0,0],"7":[0,0,0],"8":[0,0,1],"9":[0,0,0],"10":[0,0,1],"11":[0,0,0],"12":[0,1,0],"13":[0,0,0],"14":[0,0,255],"15":[0,1,118],"16":[0,1,255],"17":[0,0,255],"18":[16777217,0,255],"19":[1,0,255],"20":[65537,1,255],"0":[0,0,1],"p0":[-1,0],"modelhash":-265970301,"p1":[-1,0],"p10":[-1,0],"p2":[-1,0],"p3":[-1,0],"p4":[-1,0],"p5":[-1,0],"p7":[-1,0],"p6":[-1,0],"p9":[-1,0],"p8":[-1,0]},"weapons":[],"hunger":15.80829574494687,"phone_directory":[],"gaptitudes":{"physical":{"strength":30},"hacker":{"logic":0,"c++":0,"lua":0,"hacking":0},"laboratory":{"cocaine":0,"lsd":0,"weed":0},"science":{"chemicals":0,"mathematics":0}},"position":{"z":9.94322967529296,"y":-1153.960693359375,"x":-766.7114868164063},"inventory":{"wbody|WEAPON_HEAVYPISTOL":{"amount":1},"wbody|WEAPON_KNIFE":{"amount":2},"wbody|WEAPON_BAT":{"amount":1},"1":{"amount":200},"sandwich":{"amount":12},"wbody|WEAPON_SWITCHBLADE":{"amount":1},"arocola":{"amount":9},"wbody|WEAPON_PISTOL":{"amount":1},"apa":{"amount":116},"wbody|WEAPON_MACHETE":{"amount":2},"kebab":{"amount":116},"wammo|WEAPON_PISTOL":{"amount":500},"TASER":{"amount":1}},"health":188,"thirst":27.11659148989375,"groups":{"Chestor General":true,"cop":true,"Rainbow Menu":true,"recruiter":true,"ems":true,"FondatorQWWmklf":true,"user":true},"fRank":"Chestor General","fName":"Politie","cloakroom_idle":{"p10":[-1,0],"18":[33686018,2,255],"12":[0,2,0],"16":[0,2,255],"14":[0,2,255],"p6":[-1,0],"p8":[-1,0],"p0":[-1,0],"10":[0,0,2],"20":[33686018,2,255],"3":[0,0,2],"p3":[-1,0],"5":[0,0,2],"p5":[-1,0],"p7":[-1,0],"6":[0,0,2],"9":[0,1,2],"8":[0,0,2],"p1":[-1,0],"7":[0,0,2],"4":[0,0,2],"11":[0,0,2],"p9":[-1,0],"15":[0,2,228],"1":[0,0,2],"0":[0,0,2],"p4":[-1,0],"p2":[-1,0],"2":[0,0,2],"13":[0,2,0],"17":[256,2,255],"hasEquipment":true,"19":[33686018,2,255],"modelhash":1885233650}} prin ce metoda as putea sa extrag datele ex: "fRANK" : "Chestor General" sau "fLeader":1" segmentele dintre virgule cumva...mi-am luat brain dmg sry ... e ceva greu ? Quote
Kev Posted March 1, 2021 Report Posted March 1, 2021 (edited) grep Edit: Cu placere https://www.digitalocean.com/community/tutorials/using-grep-regular-expressions-to-search-for-text-patterns-in-linux Edited March 1, 2021 by Kev Quote
WIK Posted March 1, 2021 Author Report Posted March 1, 2021 in php exista functia grep ? ca daca-i dau cu system sau shell exec spune ca-i virus antivirusu Quote
SirGod Posted March 1, 2021 Report Posted March 1, 2021 <?php $data = file_get_contents("rst.json"); $parse = json_decode($data, true); echo $parse["fLeader"]; echo $parse["fRank"]; ?> Quote
Wav3 Posted March 1, 2021 Report Posted March 1, 2021 (edited) Depinde de versiunea de MySQL pe care o ai. Daca ai de la 5.7.8 (parca) in sus, atunci poti folosi functiile de MySQL pentru a trage direct din JSON. Daca nu, va trebui sa scoti tot campul si sa extragi din PHP ce te intereseaza. Daca MySQL-ul tau suporta campuri JSON, poti face select-ul cu JSON_EXTRACT(denumire_camp, $.fLeader), ceva de genu'. Ruleaza SELECT VERSION() ca sa vezi ce versiune ai. Edit #2: Din cate imi amintesc, poti face si cu expresie regulata, insa nu iti recomand. Edited March 1, 2021 by Wav3 Quote
UnixDevel Posted March 1, 2021 Report Posted March 1, 2021 49 minutes ago, SirGod said: <?php $data = file_get_contents("rst.json"); $parse = json_decode($data, true); class DataResponse extends \SplFixedArray { private $data = []; private $leader; private $rank; public function __construct(array $data){ $this->data = $data; } public function getLeader(){ return $this->data["fLeader"]; } public function getRank(){ return $this->data["fRank"]; } } $data = new DataResponse($parse); $rank = $data->getRank(); $leader = $data->getLeader(); ?> Arata mai bine asa 1 Quote
SirGod Posted March 1, 2021 Report Posted March 1, 2021 12 hours ago, lzomedia said: Arata mai bine asa Da, arata mai bine, e mai usor de adaptat pe viitor. Dar face acelasi lucru, doar intr-un mod mai complicat. Daca ii trebuie pentru ceva punctual, nu recomand. Daca vrea sa integreze asta intr-o aplicatie deja scrisa intr-un anume stil si la un anumit standard, e varianta mai buna, probabil. Sunt curios de un test array vs SplFixedArray, pe datele lui reale: http://johnciacia.com/2011/02/01/array-vs-splfixedarray/ Quote
UnixDevel Posted March 2, 2021 Report Posted March 2, 2021 tinand cont ca e doar un JSON nu are cum sa aiba sa zicem 600MB ca sa incepi sa te sperii de overhead. eu intodeauna aleg sa merg oop chiar si pentru chestii mai simple cum e asta. deoarece pe viitor imi va permite sa iau aceasta librarie si sa o rescriu pentru un alt proiect mult mai usor Quote