Jump to content

preg_match but for only a certan area


supermerc

Recommended Posts

Hi,

 

I have a cURL script that goes to a page, the page is a sort of vault that displays a bunch of items in the form of images. I want to be able to get the path to each of those image.

 

I managed to do so using this code:

 

<?php
$data = $result2;
$pattern = "/src=[\"']?([^\"']?.*(png|jpg|gif))[\"']?/i";
preg_match_all($pattern, $data, $images);
?>

 

The problem is that does that for the WHOLE page and I just want it to do it for the items in the vault.

 

Here is the page http://legacyow.comze.com/get_vault.php the items are all the broken images together near the center of the page.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/147303-preg_match-but-for-only-a-certan-area/
Share on other sites

You just have to find a unique string before and after the vault, and then cut the relevant source code out with e.g. substr() in combination with strpos(). Example:

 

Source:

<?php
$data = '<html>
<unique combination of tags>
vault text with images
<another unique combination of tags>
</html>';
$start = strpos($data, '<unique combination of tags>');
$length = strpos($data, '<another unique combination of tags>') - $start;
$vault = substr($data, $start, $length);
//vault holds "vault text with images"
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.