-2

I have a string 33#math#indonesia#Primary 2, and want to be separated into like this 33,math,indonesia,primary 2 into four parts enter image description here

  • $stringParts = explode('#','33#math#indonesia#Primary 2'); this will return string parts into array seperated with # – Ajith Dec 03 '19 at 07:41

3 Answers3

1

You can use str_replace() to replace the # with ,

Ludo
  • 158
  • 1
  • 1
  • 7
1

Use can also use implode and explode

$a = '33#math#indonesia#Primary 2';
$b = explode('#', $a);
$c = implode(',', $b);
print_r($c);

33,math,indonesia,Primary 2

Swetha Sekar
  • 249
  • 1
  • 9
0

use explode()

$array = explode('#',$string);
print_r($array);

Output:- https://3v4l.org/uCPY0

if you want to add , instead of # then use str_replace()

echo $string = str_replace('#',',',$string);

Output:- https://3v4l.org/8Mm08

Anant Kumar Singh
  • 68,309
  • 10
  • 50
  • 94