Created
October 18, 2020 16:52
-
-
Save davidkryzaniak/90698193021cca3d57c325fbbaf00d9e to your computer and use it in GitHub Desktop.
utf_hex_html_entities_decode
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 | |
/** | |
* Converts a string like "The �me is:" to "The time is:" | |
* | |
* @param string $input Your string that might have UTF-8 characters that are html encoded. | |
* @return string A cleaned string | |
*/ | |
function utf_hex_html_entities_decode($input) | |
{ | |
return preg_replace_callback("/&#x([0-9a-fA-F]{8});/", function($m){return hex2bin($m[1]);}, $input); | |
} | |
echo utf_hex_html_entities_decode("�\n"); //"fk" | |
echo utf_hex_html_entities_decode("�owers\n"); //"flowers" | |
echo utf_hex_html_entities_decode("af�liate\n"); //"affiliate" | |
echo utf_hex_html_entities_decode("�me is\n"); //"time" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment