Thomisback Posted July 19, 2008 Share Posted July 19, 2008 Hi, I have got a quick and simple question but I can't solve it. I want to extract a number inside a link, e.g.: <a href='/details.dx/sku.2695' style="text-decoration: none;"> I want to extract the number "2695" with preg_match_all although I have got no clue what to use, I tried: preg_match_all ("/a[\s]+[^>]*?href[\s]?=[\s\"\']+". "(.*?)[\"\']+.*?>"."([^<]+|.*?)?<\/a>/", $var, &$matches); but that only works for normal links Thanks Quote Link to comment https://forums.phpfreaks.com/topic/115589-preg_match_all/ Share on other sites More sharing options...
teynon Posted July 19, 2008 Share Posted July 19, 2008 <?php $string="<a href='/details.dx/sku.2695' style=\"text-decoration: none;\">Blah Blah </a>"; preg_match_all("@<[^0-9]+([0-9]+)[^0-9]+>[^<]+<[^>]+>@", $string, $results); echo "<pre>"; print_r($results); echo "</pre>"; ?> Array ( [0] => Array ( [0] => <a href='/details.dx/sku.2695' style="text-decoration: none;">Blah Blah </a> ) [1] => Array ( [0] => 2695 ) ) Quote Link to comment https://forums.phpfreaks.com/topic/115589-preg_match_all/#findComment-594231 Share on other sites More sharing options...
JasonLewis Posted July 20, 2008 Share Posted July 20, 2008 I posted the same thing in your other thread... But, just place _all at the end: $str = "<a href='/details.dx/sku.7397' style='text-decoration: none;'>"; $data = preg_match_all("/[0-9]+/",$str,$matches); print_r($matches); Quote Link to comment https://forums.phpfreaks.com/topic/115589-preg_match_all/#findComment-594562 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.