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/mbstring/core.php

Documentation is available at core.php

  1. <?php
  2. /**
  3. @version $Id: core.php,v 1.4 2006/02/25 14:07:57 harryf Exp $
  4. @package utf8
  5. @subpackage strings
  6. */
  7.  
  8. /**
  9. * Define UTF8_CORE as required
  10. */
  11. if !defined('UTF8_CORE') ) {
  12.     define('UTF8_CORE',TRUE);
  13. }
  14.  
  15. //--------------------------------------------------------------------
  16. /**
  17. * Assumes mbstring internal encoding is set to UTF-8
  18. * Wrapper around mb_strpos
  19. * Find position of first occurrence of a string
  20. @param string haystack
  21. @param string needle (you should validate this with utf8_is_valid)
  22. @param integer offset in characters (from left)
  23. @return mixed integer position or FALSE on failure
  24. @package utf8
  25. @subpackage strings
  26. */
  27. function utf8_strpos($str$search$offset FALSE){
  28.     if $offset === FALSE {
  29.         return mb_strpos($str$search);
  30.     else {
  31.         return mb_strpos($str$search$offset);
  32.     }
  33. }
  34.  
  35. //--------------------------------------------------------------------
  36. /**
  37. * Assumes mbstring internal encoding is set to UTF-8
  38. * Wrapper around mb_strrpos
  39. * Find position of last occurrence of a char in a string
  40. @param string haystack
  41. @param string needle (you should validate this with utf8_is_valid)
  42. @param integer (optional) offset (from left)
  43. @return mixed integer position or FALSE on failure
  44. @package utf8
  45. @subpackage strings
  46. */
  47. function utf8_strrpos($str$search$offset FALSE){
  48.     if $offset === FALSE {
  49.         # Emulate behaviour of strrpos rather than raising warning
  50.         if empty($str) ) {
  51.             return FALSE;
  52.         }
  53.         return mb_strrpos($str$search);
  54.     else {
  55.         if !is_int($offset) ) {
  56.             trigger_error('utf8_strrpos expects parameter 3 to be long',E_USER_WARNING);
  57.             return FALSE;
  58.         }
  59.  
  60.         $str mb_substr($str$offset);
  61.  
  62.         if FALSE !== $pos mb_strrpos($str$search) ) ) {
  63.             return $pos $offset;
  64.         }
  65.  
  66.         return FALSE;
  67.     }
  68. }
  69.  
  70. //--------------------------------------------------------------------
  71. /**
  72. * Assumes mbstring internal encoding is set to UTF-8
  73. * Wrapper around mb_substr
  74. * Return part of a string given character offset (and optionally length)
  75. @param string 
  76. @param integer number of UTF-8 characters offset (from left)
  77. @param integer (optional) length in UTF-8 characters from offset
  78. @return mixed string or FALSE if failure
  79. @package utf8
  80. @subpackage strings
  81. */
  82. function utf8_substr($str$offset$length FALSE){
  83.     if $length === FALSE {
  84.         return mb_substr($str$offset);
  85.     else {
  86.         return mb_substr($str$offset$length);
  87.     }
  88. }

Documentation generated on Mon, 05 Mar 2007 20:55:47 +0000 by phpDocumentor 1.3.1