newb Posted May 11, 2011 Share Posted May 11, 2011 <a href="user/237960-admin" class="username online" how can i make it so i can grab only the username out of this? Quote Link to comment https://forums.phpfreaks.com/topic/236153-need-help-putting-this-in-regex/ Share on other sites More sharing options...
gizmola Posted May 11, 2011 Share Posted May 11, 2011 what part of that string is the username? Quote Link to comment https://forums.phpfreaks.com/topic/236153-need-help-putting-this-in-regex/#findComment-1214167 Share on other sites More sharing options...
newb Posted May 11, 2011 Author Share Posted May 11, 2011 'admin' Quote Link to comment https://forums.phpfreaks.com/topic/236153-need-help-putting-this-in-regex/#findComment-1214168 Share on other sites More sharing options...
JAY6390 Posted May 11, 2011 Share Posted May 11, 2011 if (preg_match('%<a href="user/\d+-([^"]+)"%', $subject, $matches)) { $result = $matches[1]; } else { $result = ""; } Quote Link to comment https://forums.phpfreaks.com/topic/236153-need-help-putting-this-in-regex/#findComment-1214169 Share on other sites More sharing options...
newb Posted May 11, 2011 Author Share Posted May 11, 2011 thanks, that above code works, but it ignores the 'class="username online"' bit. i included it at the end Quote Link to comment https://forums.phpfreaks.com/topic/236153-need-help-putting-this-in-regex/#findComment-1214176 Share on other sites More sharing options...
JAY6390 Posted May 11, 2011 Share Posted May 11, 2011 fair enough. didn't think you'd need that if you have it only matching url's that start user/000000-username but yeah you can add that bit on too if you like Quote Link to comment https://forums.phpfreaks.com/topic/236153-need-help-putting-this-in-regex/#findComment-1214204 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.