Reputation: 19
I would like to get the urls from a webpage that starts with "http://example.com/category/"
from these tags below:
<td><a href="http://example.com/category/subcategory/product/257849" title="Sample Title">Test</a></td>
Note:
257849 = random number
Any suggestion would be very much appreciated.
Thanks!
Upvotes: 0
Views: 237
Reputation: 14149
preg_match_all('#http://example.com/category[^"]+#', $text, $a);
The result will be in $a
Upvotes: 0
Reputation: 145482
Just specify the fixed base URL asis in the regex, and use [\w/]+
to match any combination of letters, numbers and the / slash afterwards:
preg_match('#http://example.com/category/[\w/]+#', $text, $match);
print $match[0];
And to extract all urls at once, use preg_match_all()
instead.
Upvotes: 1