mb_str_functions.rst 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. =========================
  2. Rule ``mb_str_functions``
  3. =========================
  4. Replace non multibyte-safe functions with corresponding mb function.
  5. Warning
  6. -------
  7. Using this rule is risky
  8. ~~~~~~~~~~~~~~~~~~~~~~~~
  9. Risky when any of the functions are overridden, or when relying on the string
  10. byte size rather than its length in characters.
  11. Examples
  12. --------
  13. Example #1
  14. ~~~~~~~~~~
  15. .. code-block:: diff
  16. --- Original
  17. +++ New
  18. <?php
  19. -$a = strlen($a);
  20. -$a = strpos($a, $b);
  21. -$a = strrpos($a, $b);
  22. -$a = substr($a, $b);
  23. -$a = strtolower($a);
  24. -$a = strtoupper($a);
  25. -$a = stripos($a, $b);
  26. -$a = strripos($a, $b);
  27. -$a = strstr($a, $b);
  28. -$a = stristr($a, $b);
  29. -$a = strrchr($a, $b);
  30. -$a = substr_count($a, $b);
  31. +$a = mb_strlen($a);
  32. +$a = mb_strpos($a, $b);
  33. +$a = mb_strrpos($a, $b);
  34. +$a = mb_substr($a, $b);
  35. +$a = mb_strtolower($a);
  36. +$a = mb_strtoupper($a);
  37. +$a = mb_stripos($a, $b);
  38. +$a = mb_strripos($a, $b);
  39. +$a = mb_strstr($a, $b);
  40. +$a = mb_stristr($a, $b);
  41. +$a = mb_strrchr($a, $b);
  42. +$a = mb_substr_count($a, $b);