良い一日、
cURLとさまざまな解析手法を使用して、さまざまなWebサイトから情報を取得しています。必要に応じて、情報をスキャンするWebサイトを追加できるようにコードを作成しました。
取得される情報は次のとおりです:(情報が不正確であり、実際の価格/名前を反映していない可能性があることに注意してください)
Array
(
[website1.com] => Array
(
[0] => Array
(
[0] => 60" BRAVIA LX900 Series 3D HDTV
[1] => website1.com
[2] => 5299.99
)
[1] => Array
(
[0] => 52" BRAVIA LX900 Series 3D HDTV
[1] => website1.com
[2] => 4499.99
)
[2] => Array
(
[0] => 46" BRAVIA LX900 Series 3D HDTV
[1] => website1.com
[2] => 3699.99
)
[3] => Array
(
[0] => 40" BRAVIA LX900 Series 3D HDTV
[1] => website1.com
[2] => 2999.99
)
)
[website2.com] => Array
(
[0] => Array
(
[0] => Sony 3D 60" LX900 HDTV BRAVIA
[1] => website2.com
[2] => 5400.99
)
[1] => Array
(
[0] => Sony 3D 52" LX900 HDTV BRAVIA
[1] => website2.com
[2] => 4699.99
)
[2] => Array
(
[0] => Sony 3D 46" LX900 HDTV BRAVIA
[1] => website2.com
[2] => 3899.99
)
)
)
必要な出力は次のとおりです。
Array
(
[0] => Array
(
[Name] => 60" BRAVIA LX900 Series 3D HDTV
[website1.com] => 5299.99
[website2.com] => 5400.99
)
[1] => Array
(
[Name] => 52" BRAVIA LX900 Series 3D HDTV
[website1.com] => 4499.99
[website2.com] => 4699.99
)
[2] => Array
(
[Name] => 46" BRAVIA LX900 Series 3D HDTV
[website1.com] => 3699.99
[website2.com] => 3899.99
)
[3] => Array
(
[Name] => 40" BRAVIA LX900 Series 3D HDTV
[website1.com] => 2999.99
)
)
名前は異なる場合があるため、similar_textを使用する必要があることに注意してください。また、一部の情報がすべてのWebサイトに表示されない場合があります。テレビの名前を1つだけ選択する必要があることは承知しています。次に、最も関連性の高いソース(website1.com)のテレビ名を使用します。
これが私が機能させようとしているコードです。
<?php
$_Retreived = array(
"website1.com" => array(
array('60" BRAVIA LX900 Series 3D HDTV', 'website1.com', 5299.99),
array('52" BRAVIA LX900 Series 3D HDTV', 'website1.com', 4499.99),
array('46" BRAVIA LX900 Series 3D HDTV', 'website1.com', 3699.99),
array('40" BRAVIA LX900 Series 3D HDTV', 'website1.com', 2999.99)
),
"website2.com" => array(
array('Sony 3D 60" LX900 HDTV BRAVIA', 'website2.com', 5400.99),
array('Sony 3D 52" LX900 HDTV BRAVIA', 'website2.com', 4699.99),
array('Sony 3D 46" LX900 HDTV BRAVIA', 'website2.com', 3899.99),
)
);
$_Prices = array();
$_PricesTemp = array();
$_Sites = array("website1.com", "website2.com");
for($i = 0; $i < sizeOf($_Sites); $i++)
{
$_PricesTemp = array_merge($_PricesTemp, $_Retreived[ $_Sites[$i] ]);
}
/*
print_r($_PricesTemp);
Array
(
[0] => Array
(
[0] => 60" BRAVIA LX900 Series 3D HDTV
[1] => website1.com
[2] => 5299.99
)
[1] => Array
(
[0] => 52" BRAVIA LX900 Series 3D HDTV
[1] => website1.com
[2] => 4499.99
)
[2] => Array
(
[0] => 46" BRAVIA LX900 Series 3D HDTV
[1] => website1.com
[2] => 3699.99
)
[3] => Array
(
[0] => 40" BRAVIA LX900 Series 3D HDTV
[1] => website1.com
[2] => 2999.99
)
[4] => Array
(
[0] => Sony 3D 60" LX900 HDTV BRAVIA
[1] => website2.com
[2] => 5400.99
)
[5] => Array
(
[0] => Sony 3D 52" LX900 HDTV BRAVIA
[1] => website2.com
[2] => 4699.99
)
[6] => Array
(
[0] => Sony 3D 46" LX900 HDTV BRAVIA
[1] => website2.com
[2] => 3899.99
)
)
*/
foreach($_PricesTemp As $_KeyOne => $_EntryOne)
{
foreach(array_reverse($_PricesTemp, true) As $_KeyTwo => $_EntryTwo)
{
if ($_KeyOne != $_KeyTwo)
{
$_Percent = 0;
similar_text(strtoupper($_EntryOne[0]), strtoupper($_EntryTwo[0]), $_Percent);
if ($_Percent >= 90) //If names matches 90%+
{
echo "Similar : <b>" . $_KeyOne . "</b> " . $_EntryOne[0] . " and <b>" . $_KeyTwo . "</b> " . $_EntryTwo[0] . " Percent : " . $_Percent . "<br />";
$_Prices[] = array();
$_Prices[ sizeOf($_Prices)-1 ]['Name'] = $_EntryOne[0]; //Use the product name of the most revelant website (website1.com)
foreach($_Sites As $_Site)
{
if (isset($_EntryOne[ 1 ]) && $_EntryOne[ 1 ] == $_Site) //Check if it contains price from website1.com
{
$_Prices[ sizeOf($_Prices)-1 ][ $_Site ] = $_EntryOne[ 2 ];
}
if (isset($_EntryTwo[ 1 ]) && $_EntryTwo[ 1 ] == $_Site) //Check if it contains price from website2.com
{
$_Prices[ sizeOf($_Prices)-1 ][ $_Site ] = $_EntryTwo[ 2 ];
}
}
}
}
}
}
/*
print_r($_Prices);
Array
(
[0] => Array
(
[Name] => 60" BRAVIA LX900 Series 3D HDTV
[website1.com] => 2999.99
)
[1] => Array
(
[Name] => 60" BRAVIA LX900 Series 3D HDTV
[website1.com] => 3699.99
)
[2] => Array
(
[Name] => 60" BRAVIA LX900 Series 3D HDTV
[website1.com] => 4499.99
)
[3] => Array
(
[Name] => 52" BRAVIA LX900 Series 3D HDTV
[website1.com] => 2999.99
)
[4] => Array
(
[Name] => 52" BRAVIA LX900 Series 3D HDTV
[website1.com] => 3699.99
)
[5] => Array
(
[Name] => 52" BRAVIA LX900 Series 3D HDTV
[website1.com] => 5299.99
)
[6] => Array
(
[Name] => 46" BRAVIA LX900 Series 3D HDTV
[website1.com] => 2999.99
)
[7] => Array
(
[Name] => 46" BRAVIA LX900 Series 3D HDTV
[website1.com] => 4499.99
)
[8] => Array
(
[Name] => 46" BRAVIA LX900 Series 3D HDTV
[website1.com] => 5299.99
)
[9] => Array
(
[Name] => 40" BRAVIA LX900 Series 3D HDTV
[website1.com] => 3699.99
)
[10] => Array
(
[Name] => 40" BRAVIA LX900 Series 3D HDTV
[website1.com] => 4499.99
)
[11] => Array
(
[Name] => 40" BRAVIA LX900 Series 3D HDTV
[website1.com] => 5299.99
)
[12] => Array
(
[Name] => Sony 3D 60" LX900 HDTV BRAVIA
[website2.com] => 3899.99
)
[13] => Array
(
[Name] => Sony 3D 60" LX900 HDTV BRAVIA
[website2.com] => 4699.99
)
[14] => Array
(
[Name] => Sony 3D 52" LX900 HDTV BRAVIA
[website2.com] => 3899.99
)
[15] => Array
(
[Name] => Sony 3D 52" LX900 HDTV BRAVIA
[website2.com] => 5400.99
)
[16] => Array
(
[Name] => Sony 3D 46" LX900 HDTV BRAVIA
[website2.com] => 4699.99
)
[17] => Array
(
[Name] => Sony 3D 46" LX900 HDTV BRAVIA
[website2.com] => 5400.99
)
)
*/
?>
まず第一に、上記のコードは機能していません。どこかに指を置くことができない論理的なエラーがあるに違いありません。また、リストに3番目のWebサイトを追加した場合でも、コードが機能するとは思われません。
アイデアはありますか?私は今朝からこれに取り組んでいます。
2011-02-16を編集:
私はこの質問に賞金を追加しました。