Skip to content

Instantly share code, notes, and snippets.

@Cvar1984
Created May 3, 2018 17:41
Show Gist options
  • Save Cvar1984/1b049bfa059fe8bd6f241e1acf17de17 to your computer and use it in GitHub Desktop.
Save Cvar1984/1b049bfa059fe8bd6f241e1acf17de17 to your computer and use it in GitHub Desktop.
<?php
function ambil($text,$sebelum,$sesudah) {
$text=" ".$text;
$ini=strpos($text, $sebelum);
if($ini == 0) return "";
$ini+=strlen($sebelum);
$panjang=strpos($text,$sesudah,$ini) - $ini;
return substr($text,$ini,$panjang);
}
$url="https://www.bukalapak.com/p/handphone/hp-smartphone/7fybvh-jual-sony-z5-e6683-3-32-gb-garansi-resmi-1-tahun";
$text=file_get_contents($url);
$data=array(
"title"=> ambil($text,"<h1 class='c-product-detail__name'>","</h1>"),
"price"=> ambil($text,'data-reduced-price="','" data-installment='),
"stock"=> ambil($text,'<span class="c-label--large c-label u-mrgn-bottom--3 c-label--large c-label u-mrgn-bottom--3--sold-out">','</span>'),
"seller"=> ambil($text,'<a title="','" class')
);
?>
<table border="1">
<tr>
<td>Nama</td>
<td><?php echo $data["title"]; ?></td>
</tr>
<tr>
<td>Harga</td>
<td><?php echo $data["price"]; ?></td>
</tr>
<tr>
<td>Stock</td>
<td><?php echo $data["stock"]; ?></td>
</tr>
<tr>
<td>Seller</td>
<td><?php echo $data["seller"]; ?></td>
</tr>
<tr>
<td>Gambar</td>
<td><img src="https://s3.bukalapak.com/img/3364099601/s-300-300/Sony_Z5_E6683_3_32_GB___Garansi_Resmi_1_Tahun_.jpg" /></td>
</tr>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment