Sử dụng DOMDocument():
$html = $request->description;
libxml_use_internal_errors(true); // tắt lỗi libxml
$dom = new \DOMDocument(); // tạo một biến DOM mới
// load dữ liệu từ html
$dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
// lấy các thẻ img trong $html vừa load
$images = $dom->getElementsByTagName('img');
foreach ($images as $key => $img) {
// lấy thuộc tính src trong img tag
$img->getAttribute('src');
// xoá thuộc tính src
$img->removeAttribute('src');
// đặt thuộc tính src với giá trị mới
$img->setAttribute('src', '/storage/images/vidu.png');
}
$result = $dom->saveHTML(); // lưu lại va trả về html đã sửa
return $result;
Lấy ip của client
public function get_client_ip() {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
//ip from share internet
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
//ip pass from proxy
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
...
Không có nhận xét nào:
Đăng nhận xét