euphoric Posted April 22, 2010 Report Share Posted April 22, 2010 Sveiki ! Iesakiet lūdzu kā labāk sadalīt stringu un samest masīvā ? String : "257596":257596,"692830":692830,"1283348":1283348 Beigu rezultāts : Array ( [0] => 257596 [1] => 692830 [2] => 1283348 ) Pāldies :) Quote Link to comment Share on other sites More sharing options...
briedis Posted April 22, 2010 Report Share Posted April 22, 2010 (edited) <?php $str = '"257596":257596,"692830":692830,"1283348":1283348'; $result = array(); $arr = explode(",", $str); foreach($arr as $item){ list(,$result[]) = explode(":",$item); } print_r($result); ?> ..principā šo varētu arī ar vienu regulāro izteiksmi..., jo patterns ":\d+" mūs interesē... Edited April 22, 2010 by briedis Quote Link to comment Share on other sites More sharing options...
euphoric Posted April 22, 2010 Author Report Share Posted April 22, 2010 Oke snx, biju domājis varbūt ar regulāro butu labāk ,bet ja jau PRO iesaka šādi . Pāldies ;) Quote Link to comment Share on other sites More sharing options...
indoom Posted April 22, 2010 Report Share Posted April 22, 2010 (edited) $str = '"257596":257596,"692830":692830,"1283348":1283348'; $result = explode(',',preg_replace('/"\d+":/','',$str)); print_r($result); vai preg_match_all('/(?<=:)\d+/',$str, $result); print_r($result[0]); Edited April 22, 2010 by indoom Quote Link to comment Share on other sites More sharing options...
briedis Posted April 22, 2010 Report Share Posted April 22, 2010 $str = '"257596":257596,"692830":692830,"1283348":1283348'; $result = explode(',',preg_replace('/"\d+":/','',$str)); print_r($result); laba pieeja :) Eh, jāpamācās vēl tās regulārās... Quote Link to comment Share on other sites More sharing options...
euphoric Posted April 22, 2010 Author Report Share Posted April 22, 2010 Heh =) Nu Paldies, Paldies :) Quote Link to comment Share on other sites More sharing options...
marcis Posted April 22, 2010 Report Share Posted April 22, 2010 Šodien velk uz perversijām :D $str = '"257596":257596,"692830":692830,"1283348":1283348'; $result = array_values(json_decode('{'.$str.'}', true)); print_r($result); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.