-2

私はウェブサイトから cetrain 値をこすり取ろうとしています: http://www.gitanjalijewels.com/

次のコードを使用しています。

<?php 


$data = file_get_contents('http://www.gitanjalijewels.com/category.php?id=39');
$regex = '/GOLD RATES:: (.+?) ,/';
preg_match($regex,$data,$match);
var_dump($match); 
echo $match[1];

?>

しかし、私が得る結果は次のとおりです。

配列(0) { }

何が問題なのか特定できませんか? 誰でも私を正しい方向に向かわせることができますか?

4

3 に答える 3

1
$html = file_get_contents("http://www.gitanjalijewels.com/category.php?id=39");

$matches = array();
preg_match("/GOLD RATES::[^\>]+/", $html, $matches);
print("<pre>");
var_dump($matches);
print("</pre>");

if( count($matches) > 0 ){
    $html = $matches[0];
    $matches = array();
    preg_match_all("/\(([^:]+)\:([^\)]+)\)/", $html, $matches);

    $goldPrice = array();
    if( count($matches) > 0){
        for($i = 0; $i<count($matches[1]); $i++)
            $goldPrice[ $matches[1][$i] ] = $matches[2][$i];
    }
    print("<pre>");
    var_dump($goldPrice);
    print("</pre>");
}

result:
array(4) {
    ["24kt999"]=>
        string(9) "--Rs.2868"
    ["24kt995"]=>
        string(9) "--Rs.2841"
    ["22kt"]=>
        string(9) "--Rs.2675"
    ["18kt"]=>
        string(9) "--Rs.2236"
}
于 2013-07-26T06:32:57.493 に答える
1
$regex = '/GOLD RATES::[\s]?(.+?)[\s]?,/si';
preg_match($regex,$data,$match);
var_dump($match);

出力:

array(2) {
  [0] =>
  string(32) "GOLD RATES::(24kt999:--Rs.2868),"
  [1] =>
  string(19) "(24kt999:--Rs.2868)"
}
于 2013-07-26T06:20:40.283 に答える