aaa, bbb, ccc
Bạn đang xem: Php
Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)
You can use strpos() and substr() for this. See
Alternate approach using explode:
$arr = explode(",", $string);$string = implode(",",array_slice($arr, 0, 3);
If you don"t know exactly the number chars khổng lồ count I would suggest an Implode Explode like this:
$string = "aaa, bbb, ccc, ddd, eee, fff";$arr = explode("," , $string);$out = array();for($i = 0; $i Updatehere"s a phpfiddle
If it is specific for uptill third string than try,
$output = implode(array_slice(explode(",",$string), 0, 3),","); Demo.
$string = "aaa, bbb, ccc, ddd, eee, fff";$arr = explode(", ", $string);$arr = array_splice($arr, 0, 3);$string = implode($arr, ", ");echo $string; // = "aaa, bbb, ccc"
Thanks for contributing an answer lớn Stack Overflow!Please be sure khổng lồ answer the question. Provide details và share your research!
But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Post Your Answer Discard
Site kiến thiết / hình ảnh sản phẩm © 2022 Stack Exchange Inc; user contributions licensed under CC BY-SA. Rev2022.12.21.43127