我需要解析它们的格式是这样的文本块:解析结构化和非结构化文本的混合
Today the weather is excellent bla bla bla.
<temperature>35</temperature>.
I'm in a great mood today.
<item>Desk</item>
我想分析这样的文字,并将其翻译成它类似于一个数组是这样的:
$array[0]['text'] = 'Today the weather is excellent bla bla bla. ';
$array[0]['type'] = 'normalText';
$array[1]['text'] = '35';
$array[1]['type'] = 'temperature';
$array[2]['text'] = ". I'm in a great mood today.";
$array[2]['type'] = 'normalText';
$array[3]['text'] = 'Desk';
$array[3]['type'] = 'item';
从本质上讲,我想数组包含所有在同一顺序的文字作为原始文本,但分成两类:普通文本(意思的东西这是不是任何标记之间)以及由标签确定的其他类型,如温度,项目文字介于两者之间。
有没有办法做到这一点(即单独的文本转换为普通文本,以及其他类型,使用正则表达式),或者我幕后应该将文本转换成适当的结构化文本,如:
<normal>Today the weather is excellent bla bla bla.</normal>
<temperature>35</temperature>.
<normal> I'm in a great mood today.</normal><item>Desk</item>
在尝试解析文本之前?
无需转换它,但包含一个条目的数组每行文字? – cerealy
@cerealy有些标签可能会扩展到多条线路,如''- 可能包含描述的几行,以及项目名称 –