1

I have issues with unicode characters returning a string null within an array. This array is creating in PHP and echoed which json_encode. The problem exists within "name".

The initial object looks like:

[{"ID":"147","First Name":"Tom","Last Name":"Bishai","Registered Table Number":"34","Email Address":"tombishai@gmail.com","Phone Number":"07921130704","Amount":"800","MadeFrom":"34","Type of Transaction":"bid","Number":"22","name":null,"Gift Aid":"Yes","PIN":"1261"}]

I have used a function from another question which looks like this:

    function utf8ize($d) {
      if(is_array($d)) {
        foreach($d as $k => $v) {
          $d[$k] = utf8ize($v);
        }
      }  else if(is_string($d)) {
        return utf8_encode($d);
      }
      return $d;
    }
echo json_encode(utf8ize($arr));

This now returns a string (within the array) which looks like:

[{"ID":"147","First Name":"Tom","Last Name":"Bishai","Registered Table Number":"34","Email Address":"tombishai@gmail.com","Phone Number":"07921130704","Amount":"800","MadeFrom":"34","Type of Transaction":"bid","Number":"22","name":"JOAN MIRO \u0096 COMPOSITION IX","Gift Aid":"Yes","PIN":"1261"}]

Now I am having trouble converting this to a html entity. It will also need to apply to any other unicode characters that may appear in the database. Any help?

Many thanks!

UPDATE: Just doesn't seem to work with em dash/en dash. I haven't gone through all of the unicode characters though.

wreckit
  • 85
  • 1
  • 10
  • See this post, first: https://stackoverflow.com/questions/24500162/display-u0096-in-a-jsp, Then use something like this `echo mb_convert_encoding('–', 'UTF-8', 'HTML-ENTITIES');` – MB34 May 16 '18 at 13:25
  • @MB34 where would I use the mb_convert_encoding line? – wreckit May 16 '18 at 15:22
  • From the code in your question, I don't see where the `Name` value is being passed. I would convert it before sending `$d` to the `utf8ize()` function. – MB34 May 16 '18 at 17:19

0 Answers0