用正则表达式替换字符串

$string = "a;b;c\nd;e;f";
// $1, $2 and $3 represent the first, second and third capturing groups
echo preg_replace("(^([^;]+);([^;]+);([^;]+)$)m", "$3;$2;$1", $string);

输出

c;b;a
f;e;d

搜索分号之间的所有内容并反转顺序。