-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregex.php
More file actions
76 lines (60 loc) · 2.08 KB
/
regex.php
File metadata and controls
76 lines (60 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
$user_id="tauseef";
$username="root";
//$password="admin";
$database="search";
mysql_connect("localhost",$username,"");
@mysql_select_db($database) or die( "Unable to select database");
error_reporting (E_ERRORS);
?>
<?php
mysql_query("DELETE FROM `deal`");
mysql_query("DELETE FROM `product`");
$array1 = array("camera","phone","laptop","mouse","lens","books");
//$query=$_GET["search"];
foreach ($array1 as $i => $value) {
$testfile=file_get_contents("http://www.dealstobuy.com/search?q=$array1[$i]");
$testfile=str_replace("\n", " ", $testfile);
$regex1="@<a[^>]*href=\"([^\"]+)\">([^<]*)</a>[^<]*<strong>\s*([^\s<]*)\s*</strong>.*<div class=\"image\">.*<a class=\"jumplink\".*<img src=\"([^\"]+)\".*<p class=\"description\">(.*)</p>@U";
$count=preg_match_all($regex1, $testfile, $matches);
array_shift($matches);
$items=array();
for($i=0; $i<$count; $i++){
$items[]=array(
"Deal_Link" => $matches[0][$i],
"Name" => $matches[1][$i],
"Price" => $matches[2][$i],
"Image_Link" => $matches[3][$i],
"Description" => htmlentities($matches[4][$i]));
}
mysql_query("INSERT INTO product(`Name`) VALUES('".$query."')");
$product = mysql_query("SELECT * FROM `product` WHERE `Name`='".$query."'");
$prod= mysql_fetch_array($product);
echo $prod['Name'];
echo "$count matches found:<br/>";
foreach($items as $item){
echo "<dl>";
foreach($item as $key => $val)
{
echo "<dt>$key</dt><dd>$val</dd>";
if($key == "Name")
{
$Name = mysql_escape_string($val);
}
if($key == "Deal_Link")
$deal = mysql_escape_string($val);
if($key == "Description")
$desc = mysql_escape_string($val);
if($key == "Image_Link")
$img = mysql_escape_string($val);
if($key == "Price")
$price = mysql_escape_string($val);
}
$priceOnly = substr($price,1);
$priceFloat = (float)$priceOnly;
$deal = "http://deals2buy.com/".$deal;
mysql_query("INSERT INTO deal(`Product_ID`,`Name`,`Deal_Link`,`Image_Link`,`Price`,`Description`) VALUES('". $prod['Product_ID']."','".$Name."','".$deal."','".$img."','".$priceFloat."','".$desc."')");
echo "</dl>";
}
}
?>