Jump to content

[SOLVED] preg_match help..


poofried

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/172894-solved-preg_match-help/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.