php 从文本中删除内容类型

标签 php regex

我有一些文本,如 $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/

相关文章:

php - 在 php + mysql 中重新安排与 latest on top 的对话

正则表达式在 sed 中重复缩进

java - 如何以这种格式编写java模式 : any characters (int, int) (int,int) number number any number of (int,int,int)

PHP 准备语句插入查询

php - 如何从 PHP session 数组中删除变量

regex - .NET 的 URL 解析 PCRE 正则表达式的等价物

java - 无法使用 Java 和 Regex 打印文件中的单词

regex - 如何在R中的单词之间替换特殊字符

php - 如何在 MySQL 查询中使用带有单引号值的数组?

javascript - POST HTML图像对象作为文件