![](https://forums.phpfreaks.com/uploads/set_resources_1/84c1e40ea0e759e3f1505eb1788ddf3c_pattern.png)
shaunie
-
Posts
52 -
Joined
-
Last visited
Posts posted by shaunie
-
-
Hi,
I have the written the following code which scrapes price info from a website:
$url = 'http://www.mydomain.com'; $html = file_get_contents($url); $pattern = '/<span class="price">(.*?)<\/span>/'; preg_match_all($pattern, $html, $matches); print_r($matches);
It works well however I need to add in the delivery cost to each array element with a different pattern:
/<span class="delivery">(.*?)<\/span>/';
Any idea how i can do this so each array element has both the price and delivery costs in a two dimensional array?
Thanks for your advice
Data Scraping with preg_match_all()
in PHP Coding Help
Posted
Hi,
Thanks for your reply, it works great, the problem I have now found is that some of the prices on this site have free delivery and in this case the html is different: <span class="free_delivery">
Is there a way I can match up the elements in the array correctly in this scenario?