-1

i am trying to get infos from another site.

<td>
    <?php
    $site=file_get_contents("$link");
    $price='#<div class="price_a">(.*?)<\/div>#si';
    preg_match_all($price,$site,$pricelist);
    for ($a=0; $a<1; $a++){
        echo $pricelist[1][$a];
    }
    ?>
</td>

<td>
    <?php
    $site=file_get_contents("$link");
    $price='#<div class="price_a">(.*?)<\/div>#si';
    preg_match_all($price,$site,$pricelist);
    for ($a=1; $a<2; $a++){
        echo $pricelist[1][$a];
    }
    ?>
</td>

But in the source code there are also tags like <div class="price_m"> or <div class="price_n">

How can i take all tags from this site and use it in tags?

Thanks...

Get Off My Lawn
  • 34,175
  • 38
  • 176
  • 338
Samet
  • 27
  • 2

2 Answers2

0

Not sure if I understood you properly, but why not just use a wildcard on the class name, too?

<td>
<?php
$site=file_get_contents("$link");
$price='#<div class="price_[a-z]">(.*?)<\/div>#si';
preg_match_all($price,$site,$pricelist);
for ($a=0; $a<1; $a++){
echo $pricelist[1][$a];
}
?>
</td>

<td>
<?php
$site=file_get_contents("$link");
$price='#<div class="price_[a-z]">(.*?)<\/div>#si';
preg_match_all($price,$site,$pricelist);
for ($a=1; $a<2; $a++){
echo $pricelist[1][$a];
}
?>
</td>
0

For parsing HTML string i think best is to use PHP Simple HTML DOM Parser. It has jQuery style selectors which are very easy to use.

// Create DOM from URL or file
$html = file_get_html($link);

foreach($html->find('div.price_a') as $price_a) {
  // all div.price_a
}
foreach($html->find('div.price_m') as $price_m) {
  // all div.price_m
}
foreach($html->find('div.price_n') as $price_n) {
  // all div.price_n
}
Irfan DANISH
  • 8,349
  • 12
  • 42
  • 67