christo16 Posted November 11, 2007 Share Posted November 11, 2007 Hello All, I'm am pulling a page with file_get_contents and I want to use preg_match to search the page to find the url that matches the STRING: <a href="http://www.example.com/[0-9][0-9][0-9][0-9]">STRING</a> So I have whatever STRING is, but I want to find the URL which has some numbers on the end of it, represented by the [0-9]*4 at the end of the example. Is preg_match the best for that? Regex is confusing me, I've tried a few things and they didn't seem to work. Any help is appreciated! Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/76830-should-i-use-preg_match/ Share on other sites More sharing options...
Lumio Posted November 11, 2007 Share Posted November 11, 2007 Yes preg_match is your friend <?php $str = 'some text and the link: <a href="http://www.example.com/yeah/20">test</a>'; preg_match_all('/\<a href=".*?[\d]+">.*?</a>/', $str, $match); /* the string must contain a link starting with <a href=" followed by any sign then followed by a digit and ends up with ">, any sign and </a> */ print_r($match); ?> Quote Link to comment https://forums.phpfreaks.com/topic/76830-should-i-use-preg_match/#findComment-389150 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.