PageRenderTime 23ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/includes/class/str.class.php

http://adminserv.googlecode.com/
PHP | 110 lines | 59 code | 14 blank | 37 comment | 4 complexity | c6411bb7c659aee000008283621f57b7 MD5 | raw file
  1. <?php
  2. /**
  3. * Class Str
  4. *
  5. * Méthodes de traitement de chaines de caractčres
  6. */
  7. abstract class Str {
  8. /**
  9. * Formatage de la taille
  10. *
  11. * @param int $size -> Taille
  12. * @return string
  13. */
  14. public static function formatSize($size){
  15. // unités
  16. $u = array('octets', 'Ko', 'Mo', 'Go', 'To');
  17. $i = 0;
  18. $m = 0;
  19. // division par 1024
  20. while($size >= 1){
  21. $m = $size;
  22. $size /= 1024;
  23. $i++;
  24. }
  25. if(!$i){ $i=1; }
  26. $d = explode('.', $m);
  27. // s'il y a des décimales
  28. if($d[0] != $m){
  29. $m = number_format($m, 1, ',', ' ');
  30. }
  31. return $m.' '.$u[$i-1];
  32. }
  33. /**
  34. * Modifie les antislashes d'un lien local en slashes pour usage web
  35. *
  36. * @param string $path -> Le chemin ŕ modifier
  37. * @return string
  38. */
  39. public static function toSlash($path){
  40. $out = null;
  41. if( strstr($path, '\\') ){
  42. $newPath = explode('\\', $path);
  43. foreach($newPath as $part){
  44. $out .= $part.'/';
  45. }
  46. $out = substr($out, 0, -1);
  47. }
  48. else{
  49. $out = $path;
  50. }
  51. return $out;
  52. }
  53. /**
  54. * Remplace ou supprime les caractčres spéciaux
  55. *
  56. * @param string $str -> La chaine de caractčres
  57. */
  58. public static function replaceSpecialChars($str){
  59. // Listes
  60. $toRemove = array(
  61. "'", '"', '&', '<', '>', '+', '=', '*', '/', '˛', '~', '#', '{', '[', '(', '|', '`', '\\', '^', '@', ')', ']', '}', '¨', '$', 'Ł', '¤',
  62. '!', '%', '§', ':', ';', ',', '?', 'Ť', 'ť', '“', '”', '„', '…', 'Ą', 'ż', '‘', '’', 'ˆ', '˜', '¸', 'ˇ', '•', 'Ż', '?', '—', 'Ś', '†',
  63. '‡', 'ś', 'Š', 'Ž', '™', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
  64. '?', '?', '?', '?', '?', '?', '?', '?', '?', '°', '?', '?', '?', '?', '?', 'ą', '×', '÷', '?', '‰', 'ź', '˝', 'ž', 'š', 'ł', 'ş', 'Ş',
  65. '?', '?', '?', '?', '?', '?', '?', 'Ź', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
  66. '?', '?', '?'
  67. );
  68. $toDash = array(
  69. ' ', ' '
  70. );
  71. // Remplacement
  72. $str = trim($str);
  73. $str = str_replace($toRemove, '', $str);
  74. $str = str_replace($toDash, '-', $str);
  75. return $str;
  76. }
  77. /**
  78. * Remplace les caractčres accentués par leurs caractčres normal
  79. *
  80. * @param string $str -> La chaine de caractčres
  81. */
  82. public static function replaceAccentChars($str){
  83. $str = utf8_decode($str);
  84. $str = strtr($str, utf8_decode('ŔÁÂĂÄĹ??ŕáâăäĺ??ţĐŇÓÔŐÖŘňóôőöřČÉĘËčéęë€?ƒÇç˘ĚÍÎĎěíîďŮÚŰÜ?ůúűüľ?˙ýýŸÝĽŃń?????'), 'AAAAAAAAaaaaaaaBbDOOOOOOooooooEEEEeeeeEefCccIIIIiiiiUUUUUuuuuuuyyyYYYNnnRrpt');
  85. return utf8_encode($str);
  86. }
  87. /**
  88. * Remplace ou supprime les caractčres spéciaux et remplace les caractčres accentués
  89. *
  90. * @param string $str -> La chaine de caractčres
  91. */
  92. public static function replaceChars($str){
  93. return self::replaceSpecialChars( self::replaceAccentChars($str) );
  94. }
  95. }
  96. ?>