我有想要以特定样式格式化的字符串(文本、数字、标点符号等)。
我有这个:
1. TOC 1.1 Chapter 1.1 1.2 Chapter 1.2 1.3 Chapter 1.3 2. Automation 2.1 This is Chapter 2.1 2.2 Chapter 2.2 is it's name 3. Mechanics 3.1 Chapter 3.2 Some Chapter 3.2a Sub-chapter of 3.2 3.2b Sub-chapter of 3.2 chapter
需要这个:
1. TOC
1.1 Chapter 1.1
1.2 Chapter 1.2
1.3 Chapter 1.3
2. Automation
2.1 This is Chapter 2.1
2.2 Chapter 2.2 is it's name
3. Mechanics
3.1 Chapter
3.2 Some Chapter
3.2a Sub-chapter of 3.2
3.2b Sub-chapter of 3.2 chapter
试过这个:
$text = preg_replace('/([0-9])/', "\n\t$1", $text);
得到这个(不正确的输出):
1. TOC
1.
1 Chapter
1.
1
1.
2 Chapter
1.
2
1.
3 Chapter
1.
3
2. Automation
2.
1 This is Chapter
2.
1
2.
2 Chapter
2.
2 is it's name
3. Mechanics
3.
1 Chapter
3.
2 Some Chapter
3.
2a Sub-chapter of
3.
2
3.
2b Sub-chapter of
3.
2 chapter
如何解决此问题,以便以我需要的格式显示输出?