Created
August 24, 2011 20:38
-
-
Save douglasmiranda/1169157 to your computer and use it in GitHub Desktop.
How to get substring from accented words (UTF-8)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* How to get substring UTF-8 characters | |
*/ | |
// If you try something like this | |
$utf_8_characters = 'Sábado'; | |
echo substr($utf_8_characters, 0, 3); | |
// you get something like "Sá", but not "Sáb" | |
// now, if you just use mb_substr | |
// http://www.php.net/manual/en/function.mb-substr.php | |
echo mb_substr($utf_8_characters, 0, 3, 'UTF-8'); | |
// ..and we get this time: "Sáb" | |
// Now, we ok :) | |
// NOTE: For more about Multibyte String | |
// Functions: http://www.php.net/manual/en/ref.mbstring.php | |
?> |
You save my life
Excellent. Thanks for that :D
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you :)