Support Joomla!

Packages

Package: utf8

License

Content on this site is copyright © 2005 - 2008 Open Source Matters Inc and can be used in accordance with the Joomla! Electronic Documentation License. Some parts of this website may be subject to other licenses.
Source code for file /phputf8/mbstring/core.php

Documentation is available at core.php

  1. <?php
  2. /**
  3. @version $Id: core.php 10381 2008-06-01 03:35:53Z pasamio $
  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(strlen($str&& strlen($search)) {
  29.         if $offset === FALSE {
  30.             return mb_strpos($str$search);
  31.         else {
  32.             return mb_strpos($str$search$offset);
  33.         }
  34.     else return FALSE;
  35. }
  36.  
  37. //--------------------------------------------------------------------
  38. /**
  39. * Assumes mbstring internal encoding is set to UTF-8
  40. * Wrapper around mb_strrpos
  41. * Find position of last occurrence of a char in a string
  42. @param string haystack
  43. @param string needle (you should validate this with utf8_is_valid)
  44. @param integer (optional) offset (from left)
  45. @return mixed integer position or FALSE on failure
  46. @package utf8
  47. @subpackage strings
  48. */
  49. function utf8_strrpos($str$search$offset FALSE){
  50.     if $offset === FALSE {
  51.         # Emulate behaviour of strrpos rather than raising warning
  52.         if empty($str) ) {
  53.             return FALSE;
  54.         }
  55.         return mb_strrpos($str$search);
  56.     else {
  57.         if !is_int($offset) ) {
  58.             trigger_error('utf8_strrpos expects parameter 3 to be long',E_USER_WARNING);
  59.             return FALSE;
  60.         }
  61.  
  62.         $str mb_substr($str$offset);
  63.  
  64.         if FALSE !== $pos mb_strrpos($str$search) ) ) {
  65.             return $pos $offset;
  66.         }
  67.  
  68.         return FALSE;
  69.     }
  70. }
  71.  
  72. //--------------------------------------------------------------------
  73. /**
  74. * Assumes mbstring internal encoding is set to UTF-8
  75. * Wrapper around mb_substr
  76. * Return part of a string given character offset (and optionally length)
  77. @param string 
  78. @param integer number of UTF-8 characters offset (from left)
  79. @param integer (optional) length in UTF-8 characters from offset
  80. @return mixed string or FALSE if failure
  81. @package utf8
  82. @subpackage strings
  83. */
  84. function utf8_substr($str$offset$length FALSE){
  85.     if $length === FALSE {
  86.         return mb_substr($str$offset);
  87.     else {
  88.         return mb_substr($str$offset$length);
  89.     }
  90. }

Documentation generated on Sun, 21 Dec 2008 20:43:54 +0000 by phpDocumentor 1.3.1