0

I am trying to get a value from an array. But it always returns non-sense. Is it because it's a Chinese string? How can I get the first value out of "$custom_field_value[ 'value' ]"? I tried so many ways and really can't figure it out... Thank you very much for your help!!

foreach ( $rating_result[ 'custom_field_values' ] as $custom_field_value ) {
    var_dump($custom_field_value[ 'value' ]);
    //return: string(15) "蠻認真的!"string(5) "okok!"
    $value_text      = stripslashes( $custom_field_value[ 'value' ][0] );
    echo $value_text;
    //return: �o                    
}
Erin Lin
  • 75
  • 5
  • have you looked at iconv and using the ignore flag? – Professor Abronsius Jul 22 '15 at 10:02
  • try encoding your string to UTF-8 with http://php.net/manual/en/function.mb-convert-encoding.php before passing to stripslashes. – mim. Jul 22 '15 at 10:03
  • possible duplicate of [How to properly display Chinese characters in PHP?](http://stackoverflow.com/questions/13496271/how-to-properly-display-chinese-characters-in-php) – Florian Jul 22 '15 at 10:15
  • @Florian If the first var_dump is displaying the right characters, then it's not a header issue. – vard Jul 22 '15 at 10:23
  • I trid to echo utf8_encode($value_text); It still returns no-sense... Or, did I target the wrong thing? I am a php beginner... Am I writing a valid code? Thank you all! – Erin Lin Jul 22 '15 at 10:26
  • Do this before stripslashes. – vard Jul 22 '15 at 10:27
  • I put echo utf8_encode($custom_field_value[ 'value' ][0] ); echo $custom_field_value[ 'value' ][0]; before the stripslashes, within the foreach. They both return non-sense, è�èooo. – Erin Lin Jul 22 '15 at 10:32
  • utf8_encode only encodes from ISO-8859-1 to UTF-8. So you need to use mb_convert_encoding. – mim. Jul 22 '15 at 11:17

0 Answers0