Tonic-_- Posted August 8, 2009 Share Posted August 8, 2009 Well anyways its simple.. I'm trying to addon to a IRC bot I been working on but can't get any luck with this script captuuring usernames and storing it into arrays... I'm using preg_match_all to search for : and anything after it and then store it into $matches... Codex <?php preg_match_all("% .*?)%si", $read2[0], $matches); $names = $matches['1']; ?> Basically this is how the IRC prints out the name <Tonic> bye <UniBot> Good bye :Tonic!tonic@rox-ECDA17E4.sta.embarqhsd.net I want to get the name after : So far I get blank arrays... Quote Link to comment https://forums.phpfreaks.com/topic/169308-solved-cant-seem-to-capture-a-search-into-arrays/ Share on other sites More sharing options...
TeNDoLLA Posted August 8, 2009 Share Posted August 8, 2009 This should work if there is always an exclamation mark after the name. <?php $str = '<Tonic> bye <UniBot> Good bye :Tonic!tonic@rox-ECDA17E4.sta.embarqhsd.net'; preg_match('/:(.*)!/', $str, $matches); var_dump($matches[1]); // "Tonic" Quote Link to comment https://forums.phpfreaks.com/topic/169308-solved-cant-seem-to-capture-a-search-into-arrays/#findComment-893417 Share on other sites More sharing options...
Tonic-_- Posted August 8, 2009 Author Share Posted August 8, 2009 Well that got pretty close.. I had to implode the array back into a string but it prints out :Tonic!Tonic So i'm going to work with it do a few bits of trimming and see if i can get it. Alright I got it.. Imploded it and separated by , then exploded back into a array and separated the strings by , Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/169308-solved-cant-seem-to-capture-a-search-into-arrays/#findComment-893420 Share on other sites More sharing options...
TeNDoLLA Posted August 8, 2009 Share Posted August 8, 2009 There is two cells in that array. $matches[0] = ':Tonic!' and $matches[1] = 'Tonic' Thats why you use the $matches[1] value. Not whole array together. And why you want to implode the array if you jsut want to get the name out of it? Quote Link to comment https://forums.phpfreaks.com/topic/169308-solved-cant-seem-to-capture-a-search-into-arrays/#findComment-893422 Share on other sites More sharing options...
Tonic-_- Posted August 8, 2009 Author Share Posted August 8, 2009 There is two cells in that array. $matches[0] = ':Tonic!' and $matches[1] = 'Tonic' Thats why you use the $matches[1] value. Not whole array together. And why you want to implode the array if you jsut want to get the name out of it? hh that slipped my mind, been writing the bot all day that my brain is wore out. So i'll add that to trim it down some in the coding thanks man! Quote Link to comment https://forums.phpfreaks.com/topic/169308-solved-cant-seem-to-capture-a-search-into-arrays/#findComment-893424 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.