ShivaGupta Posted October 25, 2013 Share Posted October 25, 2013 Want to explode A from B Tryed myself but no luck plz help A PB4CwyDzE6FnnqDrnEoEPWIuC9_uWV B u":"PB4CwyDzE6FnnqDrnEoEPWIuC9_uWV"}] Quote Link to comment https://forums.phpfreaks.com/topic/283283-a-little-help-plz/ Share on other sites More sharing options...
requinix Posted October 25, 2013 Share Posted October 25, 2013 That looks like JSON. json_decode Quote Link to comment https://forums.phpfreaks.com/topic/283283-a-little-help-plz/#findComment-1455440 Share on other sites More sharing options...
ShivaGupta Posted October 25, 2013 Author Share Posted October 25, 2013 That looks like JSON. json_decode $json = 'u":"PB4CwyDzE6FnnqDrnEoEPWIuC9_uWV"}]'; var_dump(json_decode($json)); var_dump(json_decode($json, true)); I AM GETING NULL NULL Quote Link to comment https://forums.phpfreaks.com/topic/283283-a-little-help-plz/#findComment-1455443 Share on other sites More sharing options...
Ch0cu3r Posted October 25, 2013 Share Posted October 25, 2013 Where is this 'u":"PB4CwyDzE6FnnqDrnEoEPWIuC9_uWV"}] snippet of code from? You need to make it valid json syntax in order to decode it with json_decode You can do $json = '[{"u":"PB4CwyDzE6FnnqDrnEoEPWIuC9_uWV"}]'; $data = json_decode($json, true); echo $data[0]['u']; Quote Link to comment https://forums.phpfreaks.com/topic/283283-a-little-help-plz/#findComment-1455444 Share on other sites More sharing options...
ShivaGupta Posted October 25, 2013 Author Share Posted October 25, 2013 (edited) Where is this 'u":"PB4CwyDzE6FnnqDrnEoEPWIuC9_uWV"}] snippet of code from? You need to make it valid json syntax in order to decode it with json_decode You can do $json = '[{"u":"PB4CwyDzE6FnnqDrnEoEPWIuC9_uWV"}]'; $data = json_decode($json, true); echo $data[0]['u']; here is my code if ( preg_match("/u\"\.*?)}/i", $html,$matches) ) { $user = $matches[0]; echo "<font color=green><b>".$user."</b><br></font>"; } else { echo "A match was not found."; } //returned u":"PB4CwyDzE6FnnqDrnEoEPWIuC9_uWV"} //need only PB4CwyDzE6FnnqDrnEoEPWIuC9_uWV Edited October 25, 2013 by ShivaGupta Quote Link to comment https://forums.phpfreaks.com/topic/283283-a-little-help-plz/#findComment-1455445 Share on other sites More sharing options...
Ch0cu3r Posted October 25, 2013 Share Posted October 25, 2013 (edited) In that case use $user = $matches[1]; Edited October 25, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/283283-a-little-help-plz/#findComment-1455446 Share on other sites More sharing options...
ShivaGupta Posted October 25, 2013 Author Share Posted October 25, 2013 (edited) In that case use $user = $matches[1]; with this $user = $matches[1]; i am geting "PB4CwyDzE6FnnqDrnEoEPWIuC9_uWV" //how to remoove " from string ? Edited October 25, 2013 by ShivaGupta Quote Link to comment https://forums.phpfreaks.com/topic/283283-a-little-help-plz/#findComment-1455449 Share on other sites More sharing options...
Solution Ch0cu3r Posted October 25, 2013 Solution Share Posted October 25, 2013 you can use trim $user = trim($matches[1], '"'); Or change your regex to only match the text within the quotes if ( preg_match('/u":"([a-z0-9_]+)"}/i', $html,$matches) ) Quote Link to comment https://forums.phpfreaks.com/topic/283283-a-little-help-plz/#findComment-1455452 Share on other sites More sharing options...
ShivaGupta Posted October 25, 2013 Author Share Posted October 25, 2013 (edited) you can use trim $user = trim($matches[1], '"'); Or change your regex to only match the text within the quotes if ( preg_match('/u":"([a-z0-9_]+)"}/i', $html,$matches) ) with this $user = trim($matches[1], '"'); my provlem solved...... "Thanks a lot" Edited October 25, 2013 by ShivaGupta Quote Link to comment https://forums.phpfreaks.com/topic/283283-a-little-help-plz/#findComment-1455455 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.