Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: utf8

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /phputf8/trim.php

Documentation is available at trim.php

  1. <?php
  2. /**
  3. @version $Id: trim.php,v 1.1 2006/02/25 13:50:17 harryf Exp $
  4. @package utf8
  5. @subpackage strings
  6. */
  7.  
  8. //---------------------------------------------------------------
  9. /**
  10. * UTF-8 aware replacement for ltrim()
  11. * Note: you only need to use this if you are supplying the charlist
  12. * optional arg and it contains UTF-8 characters. Otherwise ltrim will
  13. * work normally on a UTF-8 string
  14. @author Andreas Gohr <[email protected]>
  15. @see http://www.php.net/ltrim
  16. @see http://dev.splitbrain.org/view/darcs/dokuwiki/inc/utf8.php
  17. @return string 
  18. @package utf8
  19. @subpackage strings
  20. */
  21. function utf8_ltrim$str$charlist FALSE {
  22.     if($charlist === FALSEreturn ltrim($str);
  23.  
  24.     //quote charlist for use in a characterclass
  25.     $charlist preg_replace('!([\\\\\\-\\]\\[/^])!','\\\${1}',$charlist);
  26.  
  27.     return preg_replace('/^['.$charlist.']+/u','',$str);
  28. }
  29.  
  30. //---------------------------------------------------------------
  31. /**
  32. * UTF-8 aware replacement for rtrim()
  33. * Note: you only need to use this if you are supplying the charlist
  34. * optional arg and it contains UTF-8 characters. Otherwise rtrim will
  35. * work normally on a UTF-8 string
  36. @author Andreas Gohr <[email protected]>
  37. @see http://www.php.net/rtrim
  38. @see http://dev.splitbrain.org/view/darcs/dokuwiki/inc/utf8.php
  39. @return string 
  40. @package utf8
  41. @subpackage strings
  42. */
  43. function utf8_rtrim$str$charlist FALSE {
  44.     if($charlist === FALSEreturn rtrim($str);
  45.  
  46.     //quote charlist for use in a characterclass
  47.     $charlist preg_replace('!([\\\\\\-\\]\\[/^])!','\\\${1}',$charlist);
  48.  
  49.     return preg_replace('/['.$charlist.']+$/u','',$str);
  50. }
  51.  
  52. //---------------------------------------------------------------
  53. /**
  54. * UTF-8 aware replacement for trim()
  55. * Note: you only need to use this if you are supplying the charlist
  56. * optional arg and it contains UTF-8 characters. Otherwise trim will
  57. * work normally on a UTF-8 string
  58. @author Andreas Gohr <[email protected]>
  59. @see http://www.php.net/trim
  60. @see http://dev.splitbrain.org/view/darcs/dokuwiki/inc/utf8.php
  61. @return string 
  62. @package utf8
  63. @subpackage strings
  64. */
  65. function utf8_trim$str$charlist FALSE {
  66.     if($charlist === FALSEreturn trim($str);
  67.     return utf8_ltrim(utf8_rtrim($str$charlist)$charlist);
  68. }

Documentation generated on Mon, 05 Mar 2007 21:29:46 +0000 by phpDocumentor 1.3.1