fork(26) download
  1. <?php
  2.  
  3. $string = "★ This is some text ★";
  4. $first = preg_replace_callback('/[\x{80}-\x{10FFFF}]/u', function ($m) {
  5. $char = current($m);
  6. $utf = iconv('UTF-8', 'UCS-4', $char);
  7. return sprintf("&#x%s;", ltrim(strtoupper(bin2hex($utf)), "0"));
  8. }, $string);
  9.  
  10. echo $first;
  11.  
Success #stdin #stdout 0.02s 52504KB
stdin
Standard input is empty
stdout
&#x2605; This is some text &#x2605;