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? 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? 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' 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 = ""; } 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 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 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
Archived
This topic is now archived and is closed to further replies.