【发布时间】:2015-05-10 22:57:57
【问题描述】:
$string = "
{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Tahoma;}}{\colortbl\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs18\f2\cf0 \cf0\ql
{\f2\cf2 {\ltrch <- MBisono--2/13/2015 12:01:25 PM ->}\li0\ri0\sa0\sb0\fi0\ql\par}
{\f2\cf2 {\ltrch How are you? Hope all is well. Just wanted to drop you a note that our benefits seem to be getting screwed up every time we have a new employee or if someone changes something. We have certain rules set up for Class 1 and Class 2 and it does not seem like the benefits dept is following them. }\li0\ri0\sa0\sb0\fi0\ql\par}
{\f2\cf2 {\ltrch }\li0\ri0\sa0\sb0\fi0\ql\par}
{\f2\cf2 {\ltrch Payroll is great we love Christine. It just seems like there is always something wrong with our benefits.}\li0\ri0\sa0\sb0\fi0\ql\par}
{\f2\cf2 {\ltrch }\li0\ri0\sa0\sb0\fi0\ql\par}
{\f2\cf2 {\ltrch Alexis}\li0\ri0\sa0\sb0\fi0\ql\par}
{\f2\cf2 {\ltrch }\li0\ri0\sa0\sb0\fi0\ql\par}
{\f2\cf2 {\ltrch Met with Admin and Benefits to discuss MAcGuffin's benefits. Admin has had no issues, Benefits advised that recently an employee was set up with contributions, when it should have been 100% employer paid. }\li0\ri0\sa0\sb0\fi0\ql\par}
}
}";
我有一个像上面那样的 RTF 字符串。如何将其转换为纯字符串?我希望它是这样的数组。
array(
'<- MBisono--2/13/2015 12:01:25 PM ->',
'How are you? Hope all is well. Just wanted to drop you a note that our benefits seem to be getting screwed up every time we have a new employee or if someone changes something. We have certain rules set up for Class 1 and Class 2 and it does not seem like the benefits dept is following them.',
'Payroll is great we love Christine. It just seems like there is always something wrong with our benefits.',
'Alexis',
'Met with Admin and Benefits to discuss MAcGuffin\'s benefits. Admin has had no issues, Benefits advised that recently an employee was set up with contributions, when it should have been 100% employer paid.'
)
字符串始终以“\ltrch”开头并以“}\li0”结尾。希望有帮助。谢谢正则表达式专家!
【问题讨论】:
-
也许你可以在这里找到答案,通过谷歌:webcheatsheet.com/php/reading_the_clean_text_from_rtf.php 可以在 stackoverflow 的答案中找到:stackoverflow.com/questions/9273937/rtf-to-plain-text:从这些函数中,您可以首先拆分字符串的每个部分并将其转换为纯文本...或者您可以直接使用它..sourceforge.net/projects/phprtf
-
你有没有尝试过?看起来不是这样。
-
@l'L'l,我尝试使用 preg_replace。我只需要去掉以反斜杠 \ 开头的字符串。到目前为止,我只做了这个, preg_replace("/\\/", "", $input_lines);但它只删除了反斜杠而不是之后的字符串
-
您需要在您的正则表达式中包含您想要或不想要的其他元素;这就是它的工作原理。