PHP给出尾随的"="从标准输入中读取后的每一行 [英] PHP giving a trailing "=" on each line after reading from stdin

查看:133
本文介绍了PHP给出尾随的"="从标准输入中读取后的每一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

stdin的内容因自动换行和结尾的"="而损坏,这显然破坏了我需要发布的URL.

The contents of stdin is getting corrupted with word wrapping and trailing "=" throughout which obviously breaks the URL that I need to post.

我需要从电子邮件中提取URL/链接,然后发布URL.因此,我使用在互联网上看到的标准代码片段将电子邮件发送到cpanel中的php脚本:

I need to extract a URL/link from an email then post the URL. So, I'm piping my email to a php script in cpanel using a standard code snip I've seen all over the internet:

$fd = fopen("php://stdin", "r");
$email = ""; // This will be the variable holding the data.
while (!feof($fd)) { $email .= trim(fread($fd, 1024)); }
fclose($fd);

然后将电子邮件的内容转储到文件"pipemail.txt"中以进行检查,并确保它们均能正常工作.

Then dumping the contents of the email to a file "pipemail.txt" for now to inspect it and make sure it's all working properly.

$fdw = fopen("pipemail.txt", "w+");
fwrite($fdw, $email);
fclose($fdw);

输出看起来像这样:

...
<table style=3D"width:100%" cellpadding=3D"0" cellspacing=3D"0" border=3D"0=
"><tbody><tr><td><table style=3D"background-color:#ffffff;color:#3c445a;fon=
t-family:arial;font-size:10px;font-weight:bold;width:100%" cellpadding=3D"0=
" cellspacing=3D"0">
...

我已经为此进行了整整一天的工作,我完全陷入了困境.我尝试从输入行中修剪尾随的"=",但它没有给我预期的结果.相反,它似乎从内容中看似随机的位置中删除了随机的"=".我猜这不是随机的,而是看起来只是这样,因为这不是我所期望的.如果它恰好是1024 k/char行的最后一个字符,则可能仅将其删除,但是如果这是真的,那么换行又是哪里来的呢?我对这种方法的工作方式知之甚少,无法自行解决.

I have been working on this for over a day now and I'm completely stumped. I've tried trimming the trailing "=" from incoming lines and it does not give me the expected result. Instead it seems to remove random "=" from seemingly random locations in the content. I am guessing that it is not random but it only seems so because it's not what I expect. It's probably only removing it if it happens to be the last character of the 1024 k/char line but if that is true then where else is the wordwrapping coming from? I don't know enough about how this works to trouble shoot this myself.

为什么要包装? "="来自哪里?有人有什么建议吗?

Why is it wrapping? Where are the "=" coming from? Does anyone have any suggestions?

推荐答案

电子邮件通常以引用的可打印格式进行编码( http://en.wikipedia.org/wiki/Quoted-printable )

Emails are commonly encoded in the quoted printable format (http://en.wikipedia.org/wiki/Quoted-printable)

您可以使用quoted_printable_decode()对其进行解码-这是由您的电子邮件客户端自动完成的,这就是为什么看起来php正在添加这些字符的原因.

You can decode it using quoted_printable_decode() - this is done automatically by your email client, which is why it looks like php is adding those character.

http://www.php.net/manual/zh/function.quoted-printable-decode.php

这篇关于PHP给出尾随的"="从标准输入中读取后的每一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆