2

I read unicode block string from the Wikipedia site 'https://en.wikipedia.org/wiki/Specials_(Unicode_block)', but it had nothing to do with coding, and how to dont remove sometimes appears symbols like "�", Because this string doesn't know on the PHP language.

This is my Code (php):

<?php
$str1 = 'Apple iPhone X , 64GB , Space Gray';
$title1 = substr($str1, 0, 15) . '...'; 
echo str_replace('/[\s]+/','',$title1);
echo '<br>';
$str2 = 'ipod اجدد اصدار من ابل';
$title2 = substr($str2, 0, 15) . '...'; 
echo str_replace('/[\s]+/','',$title2);
?>

out :

Apple iPhone X ...
ipod اجدد �...

How to remove question mark '�'?

dan1st
  • 12,568
  • 8
  • 34
  • 67
Negar
  • 56
  • 4

1 Answers1

0

I think the problem is not php not understanding the char but the browser.

Simply change it to &#xHEXCHAR; but don't forget to replace HEXCHAR with the hexadecimal unicode representation of your character.

If you remove the x, you'll have to use the decimal representation of the char.

For example, the character A would be &#65; or &#x41

In your case, it would be:

'ipod &#x627 &#x62C; &#x62F; &#x62F; &#x20; &#x627; &#x635; &#x62F; &#x627; &#x631; &#x20; &#x645; &#x646; &#x20; &#x627; &#x628; &#x644;'

If you do this, don't forget to adjust the substr and replace method.

Escaping the chars could also be automated by getting the unicode representation of each char and replacing the char with &#x, the hexadecimal representation and ;.

dan1st
  • 12,568
  • 8
  • 34
  • 67
  • 1
    Not sure if this answers the question or was the only answer they could accept. But the proper answer is in the duplicate. – Nigel Ren Jan 25 '20 at 07:54