<?php
namespace App\Helpers;
class Encoder {
public static function formatUrl($str,$delimiter = '-') {
if (!empty($replace)) {
$str = str_replace((array) $replace, ' ', $str);
}
$str = htmlentities($str, ENT_NOQUOTES, 'UTF-8');
$str = preg_replace('#&([A-za-z])(?:acute|cedil|caron|circ|grave|orn|ring|slash|th|tilde|uml);#', '\1', $str);
$str = preg_replace('#&([A-za-z]{2})(?:lig);#', '\1', $str); // pour les ligatures e.g. 'œ'
$str = preg_replace('#&[^;]+;#', '', $str); // supprime les autres caractères
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $str);
$clean = strtolower(trim($clean, '-'));
$clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
return $clean;
}
public static function toUppercase($str,$delimiter = '-') {
if (!empty($replace)) {
$str = str_replace((array) $replace, ' ', $str);
}
$str = htmlentities($str, ENT_NOQUOTES, 'UTF-8');
$str = preg_replace('#&([A-za-z])(?:acute|cedil|caron|circ|grave|orn|ring|slash|th|tilde|uml);#', '\1', $str);
$str = preg_replace('#&([A-za-z]{2})(?:lig);#', '\1', $str); // pour les ligatures e.g. 'œ'
$str = preg_replace('#&[^;]+;#', '', $str); // supprime les autres caractères
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $str);
return strtoupper($clean);
}
public static function fputcsvEol($handle, $array, $delimiter = ';', $enclosure = '"') {
return fputcsv($handle, $array, $delimiter, $enclosure);
if($return !== FALSE && "\n" != $eol && 0 === fseek($handle, -1, SEEK_CUR)) {
fwrite($handle, $eol);
}
return $return;
return fputs($handle, implode($delimiter, array_map(function($n) {return static::encodeCsv($n);}, $array))."\r\n");
}
public static function encodeCsv($value) {
///remove any ESCAPED double quotes within string.
$value = str_replace('\\"','"',$value);
//then force escape these same double quotes And Any UNESCAPED Ones.
$value = str_replace('"','\"',$value);
//force wrap value in quotes and return
return '"'.$value.'"';
}
public static function getExtension($fname) {
$tmp = explode('.',$fname);
return $tmp[count($tmp)-1];
}
public static function getRandomStr($n) {
$str = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomStr = '';
for ($i = 0; $i < $n; $i++) {
$index = rand(0, strlen($str) - 1);
$randomStr .= $str[$index];
}
return $randomStr;
}
public static function getRandomDigit($n) {
$str = '0123456789';
$randomStr = '';
for ($i = 0; $i < $n; $i++) {
$index = rand(0, strlen($str) - 1);
$randomStr .= $str[$index];
}
return $randomStr;
}
public static function stripTags($str,$tags=["a"]) {
$tags_to_strip = Array("p","font");
foreach ($tags as $tag)
{
$str = preg_replace("/<\\/?" . $tag . "(.|\\s)*?>/",'',$str);
}
return $str;
}
public static function priceFormat($price) {
return number_format($price, 2, ".", "");
}
public static function roundPrice($price) {
return round($price, 2);
}
}
//