StackOverflow 文件 PHP 教程 正規表示式(regexp PCRE) 用正規表示式替換字串 用正規表示式替換字串 Created: November-22, 2018 placeholderCopy$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);輸出 placeholderCopyc;b;a f;e;d搜尋分號之間的所有內容並反轉順序。 字串替換為回撥通過正規表示式將字串拆分為陣列