mb_str_functions.rst 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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);
  43. References
  44. ----------
  45. - Fixer class: `PhpCsFixer\\Fixer\\Alias\\MbStrFunctionsFixer <./../../../src/Fixer/Alias/MbStrFunctionsFixer.php>`_
  46. - Test class: `PhpCsFixer\\Tests\\Fixer\\Alias\\MbStrFunctionsFixerTest <./../../../tests/Fixer/Alias/MbStrFunctionsFixerTest.php>`_
  47. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.