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
Asked
Active
Viewed 49 times
-2
Muhamad Rahmat Setiawan
- 377
- 6
- 19
-
$stringParts = explode('#','33#math#indonesia#Primary 2'); this will return string parts into array seperated with # – Ajith Dec 03 '19 at 07:41
3 Answers
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