-2

I used a number below in my code:

$MyString = '06887558108616348​33464996​60139294';

When i'm trying to split MyString into a same pieces for example: 06887558, 10861634 so on... using substr or str_split that gives me:

06887558, 10861634, 8​3346, 4996​6, 0139294

Someone explain why this happend?!?

The Code what I have tried

$MyNewString; $n = 8; // How many you want before seperation 
$MyNewString = substr($MyString,0,$n); 
$i = $n; 
while ($i < strlen($MyString)) { 
    $MyNewString .= '-'; // Seperator Character 
    $MyNewString .= substr($MyString,$i,$n); 
    $i = $i + $n; 
} 
echo $MyNewString;
Prix
  • 19,417
  • 15
  • 73
  • 132
wertvoll
  • 19
  • 1
  • 1
  • 6

2 Answers2

1
$new_string = implode(', ', str_split($n, 8));
echo $new_string;

If you're getting funny characters in the result, then they must have been in the original string. substr and str_split don't add anything.

Barmar
  • 741,623
  • 53
  • 500
  • 612
1

add charset utf-8

add this code

echo '<meta charset="UTF-8">';

see the result I have tried

enter image description here

Md. Sahadat Hossain
  • 3,210
  • 4
  • 32
  • 55