我有一些文本,如 $text="--e89a8f234aade3345704b8477b83 text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable this is a text.";
我希望输出为 $output="this is a text. this is a text.";
还有一个例子:- $text="--14dae9340ba954ae0704b84acde9 Content-Type: text/plain; charset=ISO-8859-1 First Name: aaa Last Name: aaa --14dae9340ba954ae0704b84acde9 Content-Type: text/html; charset=ISO-8859-1 名字:James 姓氏:Cummings --14dae9340b";
输出应该是 $output="First Name: aaa Last Name: aaa";
我不知道该怎么做。
最佳答案
如果您确定字符集是 ISO-8859-1 并且字符串不包含 -- :
$a=explode("charset=ISO-8859-1",$text);
$b=explode("--",$a[1]);
$output=$b[0];
如果您仍然确定字符集,但不确定 --:
$aa=substr($text,0,30);
$a=explode("charset=ISO-8859-1",$text);
$b=explode($aa,$a[1]);
$output=$b[0];
如果您甚至不确定字符集:
$aa=substr($text,0,30);
$a=explode("charset=",$text);
$a2=explode(" ",$a[1]);
$b=explode($aa,$a2[1]);
$output=$b[0];
关于php 从文本中删除内容类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9238888/