/engine/lib/mb_wrapper.php

https://github.com/wangaiying/elgg4ysu · PHP · 233 lines · 97 code · 17 blank · 119 comment · 15 complexity · 8c270e910cd45c64cb594ac2faebf1cc MD5 · raw file

  1. <?php
  2. // if mb functions are available, set internal encoding to UTF8
  3. if (is_callable('mb_internal_encoding')) {
  4. mb_internal_encoding("UTF-8");
  5. ini_set("mbstring.internal_encoding", 'UTF-8');
  6. }
  7. /**
  8. * Parses a string using mb_parse_str() if available.
  9. * NOTE: This differs from parse_str() by returning the results
  10. * instead of placing them in the local scope!
  11. *
  12. * @param str $str The string
  13. *
  14. * @return array
  15. * @since 1.7.0
  16. */
  17. function elgg_parse_str($str) {
  18. if (is_callable('mb_parse_str')) {
  19. mb_parse_str($str, $results);
  20. } else {
  21. parse_str($str, $results);
  22. }
  23. return $results;
  24. }
  25. /**
  26. * Wrapper function for mb_split(). Falls back to split() if
  27. * mb_split() isn't available. Parameters are passed to the
  28. * wrapped function in the same order they are passed to this
  29. * function.
  30. *
  31. * @return string
  32. * @since 1.7.0
  33. */
  34. function elgg_split() {
  35. $args = func_get_args();
  36. if (is_callable('mb_split')) {
  37. return call_user_func_array('mb_split', $args);
  38. }
  39. return call_user_func_array('split', $args);
  40. }
  41. /**
  42. * Wrapper function for mb_stristr(). Falls back to stristr() if
  43. * mb_stristr() isn't available. Parameters are passed to the
  44. * wrapped function in the same order they are passed to this
  45. * function.
  46. *
  47. * @return string
  48. * @since 1.7.0
  49. */
  50. function elgg_stristr() {
  51. $args = func_get_args();
  52. if (is_callable('mb_stristr')) {
  53. return call_user_func_array('mb_stristr', $args);
  54. }
  55. return call_user_func_array('stristr', $args);
  56. }
  57. /**
  58. * Wrapper function for mb_strlen(). Falls back to strlen() if
  59. * mb_strlen() isn't available. Parameters are passed to the
  60. * wrapped function in the same order they are passed to this
  61. * function.
  62. *
  63. * @return string
  64. * @since 1.7.0
  65. */
  66. function elgg_strlen() {
  67. $args = func_get_args();
  68. if (is_callable('mb_strlen')) {
  69. return call_user_func_array('mb_strlen', $args);
  70. }
  71. return call_user_func_array('strlen', $args);
  72. }
  73. /**
  74. * Wrapper function for mb_strpos(). Falls back to strpos() if
  75. * mb_strpos() isn't available. Parameters are passed to the
  76. * wrapped function in the same order they are passed to this
  77. * function.
  78. *
  79. * @return string
  80. * @since 1.7.0
  81. */
  82. function elgg_strpos() {
  83. $args = func_get_args();
  84. if (is_callable('mb_strpos')) {
  85. return call_user_func_array('mb_strpos', $args);
  86. }
  87. return call_user_func_array('strpos', $args);
  88. }
  89. /**
  90. * Wrapper function for mb_strrchr(). Falls back to strrchr() if
  91. * mb_strrchr() isn't available. Parameters are passed to the
  92. * wrapped function in the same order they are passed to this
  93. * function.
  94. *
  95. * @return string
  96. * @since 1.7.0
  97. */
  98. function elgg_strrchr() {
  99. $args = func_get_args();
  100. if (is_callable('mb_strrchr')) {
  101. return call_user_func_array('mb_strrchr', $args);
  102. }
  103. return call_user_func_array('strrchr', $args);
  104. }
  105. /**
  106. * Wrapper function for mb_strripos(). Falls back to strripos() if
  107. * mb_strripos() isn't available. Parameters are passed to the
  108. * wrapped function in the same order they are passed to this
  109. * function.
  110. *
  111. * @return int
  112. * @since 1.7.0
  113. */
  114. function elgg_strripos() {
  115. $args = func_get_args();
  116. if (is_callable('mb_strripos')) {
  117. return call_user_func_array('mb_strripos', $args);
  118. }
  119. return call_user_func_array('strripos', $args);
  120. }
  121. /**
  122. * Wrapper function for mb_strrpos(). Falls back to strrpos() if
  123. * mb_strrpos() isn't available. Parameters are passed to the
  124. * wrapped function in the same order they are passed to this
  125. * function.
  126. *
  127. * @return int
  128. * @since 1.7.0
  129. */
  130. function elgg_strrpos() {
  131. $args = func_get_args();
  132. if (is_callable('mb_strrpos')) {
  133. return call_user_func_array('mb_strrpos', $args);
  134. }
  135. return call_user_func_array('strrpos', $args);
  136. }
  137. /**
  138. * Wrapper function for mb_strstr(). Falls back to strstr() if
  139. * mb_strstr() isn't available. Parameters are passed to the
  140. * wrapped function in the same order they are passed to this
  141. * function.
  142. *
  143. * @return bool
  144. * @since 1.7.0
  145. */
  146. function elgg_strstr() {
  147. $args = func_get_args();
  148. if (is_callable('mb_strstr')) {
  149. return call_user_func_array('mb_strstr', $args);
  150. }
  151. return call_user_func_array('strstr', $args);
  152. }
  153. /**
  154. * Wrapper function for mb_strtolower(). Falls back to strtolower() if
  155. * mb_strtolower() isn't available. Parameters are passed to the
  156. * wrapped function in the same order they are passed to this
  157. * function.
  158. *
  159. * @return string
  160. * @since 1.7.0
  161. */
  162. function elgg_strtolower() {
  163. $args = func_get_args();
  164. if (is_callable('mb_strtolower')) {
  165. return call_user_func_array('mb_strtolower', $args);
  166. }
  167. return call_user_func_array('strtolower', $args);
  168. }
  169. /**
  170. * Wrapper function for mb_strtoupper(). Falls back to strtoupper() if
  171. * mb_strtoupper() isn't available. Parameters are passed to the
  172. * wrapped function in the same order they are passed to this
  173. * function.
  174. *
  175. * @return string
  176. * @since 1.7.0
  177. */
  178. function elgg_strtoupper() {
  179. $args = func_get_args();
  180. if (is_callable('mb_strtoupper')) {
  181. return call_user_func_array('mb_strtoupper', $args);
  182. }
  183. return call_user_func_array('strtoupper', $args);
  184. }
  185. /**
  186. * Wrapper function for mb_substr_count(). Falls back to substr_count() if
  187. * mb_substr_count() isn't available. Parameters are passed to the
  188. * wrapped function in the same order they are passed to this
  189. * function.
  190. *
  191. * @return int
  192. * @since 1.7.0
  193. */
  194. function elgg_substr_count() {
  195. $args = func_get_args();
  196. if (is_callable('mb_substr_count')) {
  197. return call_user_func_array('mb_substr_count', $args);
  198. }
  199. return call_user_func_array('substr_count', $args);
  200. }
  201. /**
  202. * Wrapper function for mb_substr(). Falls back to substr() if
  203. * mb_substr() isn't available. Parameters are passed to the
  204. * wrapped function in the same order they are passed to this
  205. * function.
  206. *
  207. * @return string
  208. * @since 1.7.0
  209. */
  210. function elgg_substr() {
  211. $args = func_get_args();
  212. if (is_callable('mb_substr')) {
  213. return call_user_func_array('mb_substr', $args);
  214. }
  215. return call_user_func_array('substr', $args);
  216. }