megafu Posted February 7, 2007 Share Posted February 7, 2007 hi i need some help with this regular expression stuff. i want to get the userID . but i cant manage to get the regular the right way . thanks for any help here is the code i have: //<a class="" href="/user/userID" onMouseover="irrelevantstuff" onMouseout="irrelevantstuff"> function getInfo($var) { $preg = '*href="/user/*+"*'; preg_match_all(trim($preg), $var, $out); $keys = $out[1]; if ($keys == NULL) { die('No Match Found!'); } return $keys[0]; } Quote Link to comment Share on other sites More sharing options...
effigy Posted February 7, 2007 Share Posted February 7, 2007 Based on what you've given--the href attribute always uses double quotes--the code below will work. It needs tweaking if you want to match single quotes or no quotes at all. <pre> <?php $string = <<<STR <a class="" href="/user/bob" onMouseover="irrelevantstuff" onMouseout="irrelevantstuff"> <a class="" href="/user/suzy1" onMouseover="irrelevantstuff" onMouseout="irrelevantstuff"> STR; preg_match_all('%(?<=href="/user/)[^"]+%', $string, $matches); print_r($matches); ?> </pre> See the links in my signature for more information. Quote Link to comment 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.