function to_slug($str) {
$str = trim(mb_strtolower($str));
$str = preg_replace('/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/', 'a', $str);
$str = preg_replace('/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/', 'e', $str);
$str = preg_replace('/(ì|í|ị|ỉ|ĩ)/', 'i', $str);
$str = preg_replace('/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/', 'o', $str);
$str = preg_replace('/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/', 'u', $str);
$str = preg_replace('/(ỳ|ý|ỵ|ỷ|ỹ)/', 'y', $str);
$str = preg_replace('/(đ)/', 'd', $str);
$str = preg_replace('/[^\w\s]/', '', $str);
$str = preg_replace('/([\s]+)/', '-', $str);
return $str;
}
public function getBasename($url){
return pathinfo(parse_url($url, PHP_URL_PATH), PATHINFO_BASENAME);
}
public function downloadResource($http_URL, $file_Path, $res=false){
try{
$fp = fopen($file_Path, 'w+');
$ch = curl_init($http_URL);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
return ($res) ? file_get_contents($file_Path) : true;
} catch (Exception $e) {
die('ERROR: '.$e->getMessage());
//return $e->getMessage();
}
}