String encoding in php
To recognize the pasted character, there is a website that does that for you:
http://www.mclean.net.nz/ucf/
Just copy the character and paste it into the website to get the informative description:
There are a few function in php that convert strings into different character sets:
utf8_encode() - converts a string encoded in ISO-8859-1 to UTF-8, returns the encoded string on success, or FALSE on failure.
iconv() - If you need to convert text from any encoding to any other encoding, returns the converted string or FALSE on failure.
<?php
//some German
$utf8_sentence = 'Weiß, Goldmann, Göbel, Weiss, Göthe, Goethe und Götz';
//UK
setlocale(LC_ALL, 'en_GB');
//transliterate
$trans_sentence = iconv('UTF-8', 'ASCII//TRANSLIT', $utf8_sentence);
//gives [Weiss, Goldmann, Gobel, Weiss, Gothe, Goethe und Gotz]
//which is our original string flattened into 7-bit ASCII as
//an English speaker would do it (ie. simply remove the umlauts)
echo $trans_sentence . PHP_EOL;
//Germany
setlocale(LC_ALL, 'de_DE');
$trans_sentence = iconv('UTF-8', 'ASCII//TRANSLIT', $utf8_sentence);
//gives [Weiss, Goldmann, Goebel, Weiss, Goethe, Goethe und Goetz]
//which is exactly how a German would transliterate those
//umlauted characters if forced to use 7-bit ASCII!
//(because really ä = ae, ö = oe and ü = ue)
echo $trans_sentence . PHP_EOL;
Leave String encoding in php to:
Read more #strings posts
Best Posts From symfonydev
We have not curated any of symfonydev's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From symfonydev
- {@InheritDoc} plugin for PhpStorm
- How to implement a rollback feature
- Bug in behat 3.4.0 - No specifications found at path(s), This might be because of incorrect paths configuration in your `suites`.
- MultiUpload of files in Symfony 3.2
- Executing command line script for different environment (database)
- Validators in Symfony
- String encoding in php
- Command bus in Symfony
- Providing explicit UID (if the user is the same on client and host) at docker run will help with file permissions
- Check if there are the same values for given column