ballhogjoni Posted August 26, 2008 Share Posted August 26, 2008 I have this url and I want to extract the number our of it. How would I do that? url: http://xxxxxxxxx.com/test-test1.html Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 26, 2008 Share Posted August 26, 2008 The end of test-test? Will it always be test-test, or is that just an "example" query string that actually looks nothing like the real one? >_> If so, please show us the real string you're trying to parse so we can help better. Otherwise: <?php $str = "http://xxxxxx.com/test-test1.html"; $matches = array(); preg_match('~(test-test)([0-9]+?)\.html$~i', $str, $matches); echo $matches[2]; ?> Quote Link to comment Share on other sites More sharing options...
ballhogjoni Posted August 26, 2008 Author Share Posted August 26, 2008 Test-test will not always be the same. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 26, 2008 Share Posted August 26, 2008 Will it always be in this format: http://something.com/something-something#.html ? Show me a few URLs that you're trying to parse and I'll write something up. Quote Link to comment Share on other sites More sharing options...
ballhogjoni Posted August 26, 2008 Author Share Posted August 26, 2008 http://www.findacreditsolution.com/appliedto/balance-transfers1.html http://www.findacreditsolution.com/category/business10.html Quote Link to comment Share on other sites More sharing options...
obsidian Posted August 26, 2008 Share Posted August 26, 2008 You can just match from the ending anchor: <?php if (preg_match('/([\d]+)\.[a-z]{3,4}$/', $url, $match)) { echo "Number is $match[1]"; } ?> 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.