用正規表示式替換字串
$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
搜尋分號之間的所有內容並反轉順序。
$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
搜尋分號之間的所有內容並反轉順序。