$string = "aaa, bbb, ccc, ddd, eee, fff";
I would like to cut string after third , so i would like to get output from string:
aaa, bbb, ccc
$string = "aaa, bbb, ccc, ddd, eee, fff";
I would like to cut string after third , so i would like to get output from string:
aaa, bbb, ccc
If you don't know exactly the number chars to count I would suggest an
Implode
Explode
like this:Update
here's a phpfiddle
If it is specific for uptill third string than try,
Demo.
You can use
strpos()
andsubstr()
for this. Seehttp://php.net/substr
$string = substr($string, 0, strpos($string, ', ddd'));
Alternate approach using explode:
You can use explode() and implode() PHP functions to get it.