mds1256 Posted September 21, 2013 Share Posted September 21, 2013 I have the following string (the parts between the double quotes is dynamic so not the same length or content each time) and I need to pick out who is logged on only, don't need any of the other content. "explorer.exe","2012","Console","1","30,832 K","Running","MYDOMAIN\Administrator","0:00:02","N/A" Now, I need to get the MYDOMAIN\Administrator part only (not including the quotes) and keep this in a variable. Could someone help me out with this, i'm sure it is fairly easy for one of you regex experts to do. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/282345-help-capture-part-of-a-string-please/ Share on other sites More sharing options...
Solution .josh Posted September 21, 2013 Solution Share Posted September 21, 2013 $user = array_slice(str_getcsv($string),6,1); Quote Link to comment https://forums.phpfreaks.com/topic/282345-help-capture-part-of-a-string-please/#findComment-1450595 Share on other sites More sharing options...
ragax Posted September 22, 2013 Share Posted September 22, 2013 I am guilty of often failing to think of solutions like the one proposed by .josh, a neat solution which is a great example of when not to use regex. For example, with a regex that aimed to retrieve the 7th string by counting commas, the "30,832" would really throw things off. Quote Link to comment https://forums.phpfreaks.com/topic/282345-help-capture-part-of-a-string-please/#findComment-1450613 Share on other sites More sharing options...
mds1256 Posted September 22, 2013 Author Share Posted September 22, 2013 $user = array_slice(str_getcsv($string),6,1); Nice! Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/282345-help-capture-part-of-a-string-please/#findComment-1450742 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.