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]; } Link to comment https://forums.phpfreaks.com/topic/37527-preg_match_all/ 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. Link to comment https://forums.phpfreaks.com/topic/37527-preg_match_all/#findComment-179434 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.