Hướng dẫn viết grab đơn giản nhất

Admin

AdminAdmin is verified member.

Well-Known Member
Staff member
Administrator
Ví dụ khi muốn lấy nội dung từ trang abcxyz.com
PHP:
<?php
//Đường dẫn
$url = 'http://abcxyz.com';
//Bắt đầu lấy dữ liệu
$noidung = file_get_contents($url);
Khi bạn muốn lấy nội dung 1 đoạn, ví dụ từ abc đến cuối bài xyz)
PHP:
//Bắt đầu
$batdau = 'abc';
//Kết thúc
$ketthuc = 'xyz';
//Xử lý
$bd = explode($batdau, $noidung);
$kt = explode($ketthuc, $bd['1']);
$text = $batdau.$kt['0'].$ketthuc;
//Hiển thị đoạn văn bản lấy được
echo $text;
Đây là code đầy đủ
PHP:
<?php
//Đường dẫn
$url = 'http://abcxyz.com';
//Bắt đầu lấy dữ liệu
$noidung = file_get_contents($url);
//Bắt đầu
$batdau = 'abc';
//kết thúc
$ketthuc = 'xyz';
//Xử lý
$bd = explode($batdau, $noidung);
$kt = explode($ketthuc, $bd['1']);
$text = $batdau.$kt['0'].$ketthuc;
//Hiển thị đoạn văn bản lấy được
echo $text;
?>
Chúc các bạn thành công!
 

Facebook Comments

Similar threads

Admin
Replies
2
Views
2K
AdminAdmin is verified member.
Admin
Admin
Replies
4
Views
11K
TuongLam
TuongLam
W
Replies
4
Views
1K
cuongpro9xcuongpro9x is verified member.
cuongpro9x
Back
Top