poofried Posted September 2, 2009 Share Posted September 2, 2009 how can i make preg_match get the username inside of this and just ignoring the id number. (note: the id number always varies...) <a href="member.php?u=1">user</a> here's the code that im using atm but its not working :s <? preg_match_all('|<a href="member.php?u=([0-9])">(.*?)</a>|mU',$data,$result); ?> any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/172894-solved-preg_match-help/ Share on other sites More sharing options...
Alex Posted September 2, 2009 Share Posted September 2, 2009 I think this will work: /\<a href="member.php?u=(.+?)"\>(.+?)\<\/a\>/ Quote Link to comment https://forums.phpfreaks.com/topic/172894-solved-preg_match-help/#findComment-911226 Share on other sites More sharing options...
Psycho Posted September 2, 2009 Share Posted September 2, 2009 If the value being searched is ONLY in the format you entered and is not embedded in a larger body of text (specifically with other < or >), then this will work just fine: preg_match("/>(.*)</", $link, $matches); $username = $matches[1]; If the username is within larger bodies of text then you can use this preg_match("/<a href=\"member\.php\?u=\d+\">(.*)<\/a>/", $link, $matches); $username = $matches[1]; The will grab the 'text' of an anchor only if it is exactly formatted as you have above - also the ID must consist of one or more numbers. Quote Link to comment https://forums.phpfreaks.com/topic/172894-solved-preg_match-help/#findComment-911238 Share on other sites More sharing options...
poofried Posted September 2, 2009 Author Share Posted September 2, 2009 works fine, thanks Quote Link to comment https://forums.phpfreaks.com/topic/172894-solved-preg_match-help/#findComment-911247 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.