14,974
edits
m (→MySQL way) |
No edit summary |
||
| Line 45: | Line 45: | ||
</table> | </table> | ||
=== PHP way === | |||
PHP code<ref>[https://stackoverflow.com/questions/14674834/php-convert-string-to-hex-and-hex-to-string PHP convert string to hex and hex to string - Stack Overflow]</ref>: | |||
<pre> | |||
$string = "1234567890"; | |||
echo $string . " NOT contains BOM --> after str2hex: " . str2hex($string) . PHP_EOL; | |||
$string = "\xEF\xBB\xBF" . "1234567890"; | |||
echo $string . " contains BOM --> after str2hex: " . str2hex($string) . PHP_EOL; | |||
function str2hex($string) { | |||
$hexstr = unpack('H*', $string); | |||
return array_shift($hexstr); | |||
} | |||
</pre> | |||
Result: | |||
<pre> | |||
1234567890 NOT contains BOM --> after str2hex: 31323334353637383930 | |||
1234567890 contains BOM --> after str2hex: efbbbf31323334353637383930 | |||
</pre> | |||
=== File command way === | === File command way === | ||