修改字符串方法

This commit is contained in:
chengxl
2025-05-15 15:35:07 +08:00
parent 04d0c13ebf
commit 2cb3f6f782

View File

@@ -617,10 +617,29 @@ class Base extends Controller
}
// public function blueIntegerChange($string){
// return preg_replace_callback('/\[(\d+)\]/', function($matches) {
// var_dump($matches);
// return '<blue>[' . $matches[1] . ']</blue>';
// }, $string);
// }
public function blueIntegerChange($string){
return preg_replace_callback('/\[(\d+)\]/', function($matches) {
return '<blue>[' . $matches[1] . ']</blue>';
}, $string);
$pattern = '/\[(\d+)-(\d+)\]/';
$replacement = '[\1\2]'; // 使用反向引用 \1 和 \2 来保持数字不变,只替换中间的短横线
$result = preg_replace($pattern, $replacement, $string);
$result = preg_replace_callback('/<blue>\[-?\d+(?:,|,\s*\d+)?(?:|\s*\s*\d+)?\]<\/blue>/', function($matches) {
// if(!empty($matches[1])){
// return '['.$matches[1].']';
// }
return strip_tags($matches[0]);
}, $result);
$pattern = '/\[-?\d+(?:,|,\s*\d+)?(?:|\s*\s*\d+)?\]/';
$replacement = '<blue>$0</blue>';
$result = preg_replace($pattern, $replacement, $result);
return $result;
}
public function getBoardsForJournal($journal_id, $aar = false)