doushichi3678 2012-07-21 16:16
浏览 48
已采纳

用PHP正则表达式从电子邮件中读取链接的问题

I'm having this very weird problem, and I can't seem to figure it out.

I have a script that reads an email and grabs a username and a link (or multiple links) from the email and puts it into an array. For some reason, the links keep getting chopped off because a "= " keeps getting added for some reason. When I do a string replace on the email, before i do the regex, it doesn't replace "= ". Any idea what this problem could be??

Here is the sample email:

 @bill
 http://techcrunch.com/2012/07/20/kickstarter-flashr-wants-to-make-the-iphones-bezel-a-massive-notification-light/?grcc=88888Z0ZwdgtZ0Z0Z0Z0Z0&grcc2=835637c33f965e6cdd34c87219233711~1342828462249~fca4fa8af1286d8a77f26033fdeed202~510f37324b14c50a5e9121f955fac3fa~1342747216490~0~0~0~0~0~0~0~0~7~3~

When I echo out the body of the message I get:

 --00248c6a671acfdb9c04c558d753 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable @bill http://techcrunch.com/2012/07/20/kickstarter-flashr-wants-to-make-the-iphon= es-bezel-a-massive-notification-light/?grcc=3D88888Z0ZwdgtZ0Z0Z0Z0Z0&grcc2= =3D835637c33f965e6cdd34c87219233711~1342828462249~fca4fa8af1286d8a77f26033f= deed202~510f37324b14c50a5e9121f955fac3fa~1342747216490~0~0~0~0~0~0~0~0~7~3~ --00248c6a671acfdb9c04c558d753 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable @bill

notice the "= " which breaks the link. My regex produces:

 Array ( [0] => http://techcrunch.com/2012/07/20/kickstarter-flashr-wants-to-make-the-iphon= [1] => http://techcrunch.com/2012/07/2= [2] => http://techcrunch.com/2012= ) 

When I copy and paste the string and and run it though string replace then it replaces the "= "

Any idea what's going on?

Thanks

  • 写回答

1条回答 默认 最新

  • dousendun8411 2012-07-21 16:29
    关注

    The text is in an encoding called "Quoted Printable". Decode it first into normal text:

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度